[英]How to build a java object from multiple data sources when data is not available in all sources during the creation time?
[英]How to load JSDs from multiple sources and create a java schema object?
我有一個名為SampleRequestMessage.jsd的JSD。 在這個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"
]
}
我想要此JSD的Schema對象,以便可以針對JSON對其進行驗證。 現在如何加載父JSD的所有引用。在本例中為SampleRequestMessageProperties.jsd。 此JSD是從其中一個依賴項jar中提取的。 我可能不得不從多個文件夾中提取引用的JSD,並為父JSD創建一個Schema對象。 我怎樣才能做到這一點? 請幫忙
您可以這樣做:
{
"$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"
]
}
這將驗證以下json。
{
"messageProperties": {"test": "hello"},
"endpointURL": "test.com",
"userName": "test",
"password": "secret"
}
}
定義也可以在外部文件中。 有關更多信息: 請參閱json schmea
希望這可以幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.