简体   繁体   English

如何从多个源加载JSD并创建Java模式对象?

[英]How to load JSDs from multiple sources and create a java schema object?

I have a JSD named SampleRequestMessage.jsd . 我有一个名为SampleRequestMessage.jsd的JSD。 In this jsd i have a reference to another jsd SampleRequestMessageProperties.jsd as shown below 在这个jsd中,我引用了另一个jsd SampleRequestMessageProperties.jsd,如下所示

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "javaName": "SampleConfigureNodeRequestMessage",
  "description": "This message comes from sample-paqx and gets translated into Southbound version of this message",
  "_meta": {
     "message":"com.dell.cpsd.sample.configure.node.request",
     "version":"1.0"
  },
  "type" : "object",
  "id" : "**SampleRequestMessage.jsd**",
  "properties" : {
    "messageProperties" : {
      "type" : "object",
      "$ref" : "**SampleRequestMessageProperties.jsd**"
    },
    "endpointURL" : {
      "type" : "string"
    },
    "userName" : {
      "type" : "string"
    },
    "password" : {
      "type" : "string"
    }
  },
  "required":[
     "messageProperties",
     "endpointURL",
     "userName",
     "password"
  ]
}

I want the Schema object of this JSD so that I can validate it against a JSON. 我想要此JSD的Schema对象,以便可以针对JSON对其进行验证。 Now how can I load all the references of the Parent JSD.In this case it is SampleRequestMessageProperties.jsd. 现在如何加载父JSD的所有引用。在本例中为SampleRequestMessageProperties.jsd。 This JSD is pulled from one of the dependency jars. 此JSD是从其中一个依赖项jar中提取的。 I may have to pull the referenced JSDs from multiple folders and create a Schema object for parent JSD. 我可能不得不从多个文件夹中提取引用的JSD,并为父JSD创建一个Schema对象。 How can I do this? 我怎样才能做到这一点? Please help 请帮忙

You could do it like this: 您可以这样做:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "javaName": "SampleConfigureNodeRequestMessage",
  "description": "This message comes from sample-paqx and gets translated into Southbound version of this message",
  "_meta": {
     "message":"com.dell.cpsd.sample.configure.node.request",
     "version":"1.0"
  },"definitions": {
    "SampleRequestMessage": {
      "type": "object",
      "properties": {
        "test": { "type": "string" }
      },
      "required": ["test"]
    }
  },
  "type" : "object",
  "properties" : {
    "messageProperties" : {"$ref": "#/definitions/SampleRequestMessage"
    },
    "endpointURL" : {
      "type" : "string"
    },
    "userName" : {
      "type" : "string"
    },
    "password" : {
      "type" : "string"
    }
  },
  "required":[
     "messageProperties",
     "endpointURL",
     "userName",
     "password"
  ]
}

This would validate the following json. 这将验证以下json。

{
  "messageProperties": {"test": "hello"},
  "endpointURL":  "test.com",
    "userName": "test",
    "password": "secret"
  }
}

The definitions can also be in a external file. 定义也可以在外部文件中。 For more infos: refer json schmea 有关更多信息: 请参阅json schmea

Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当创建期间所有源中的数据都不可用时,如何从多个数据源构建 java object? - How to build a java object from multiple data sources when data is not available in all sources during the creation time? 如何从 Java 加载 JSON Schema 文件 - How to load JSON Schema file from java Java如何从来自多个源的数据推断类型 - Java how to infer type from data coming from multiple sources 如何使用Java和itext从Graphics对象创建包含多个页面的PDF - How to create a PDF with multiple pages from a Graphics object with Java and itext 如何从一个数组创建多个Java对象实例? - How do I create multiple Java object instances from an array? 如何从列表创建HashSet <Object> 通过使用Java8 Stream从对象获取多个字段值? - How to create HashSet from List<Object> by taking multiple field values from object with Java8 Stream? 如何从Java中的多个线程获取和处理对象? 如何创建Future的多个实例 - How to take and handle object from multiple threads in Java? How to create Multiple instances of Future 如何从ArrayList创建Object [] [] <Object[]> 在java中 - How to create Object[][] from ArrayList<Object[]> in java 如何从Java对象加载枚举 - How to load Enum from java object Spring Data多个数据源一个模式 - Spring Data multiple data sources one schema
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM