我有以下 json 数据对象:
{
"name": "John",
"favorite_number": 5,
"favorite_color" : "green"
}
此对象的 JSON 模式如下所示:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Person",
"description": "some description",
"type": "object",
"properties": {
"name": {
"description": "name",
"type": "string"
},
"favorite_number": {
"type": "number",
},
"favorite_color": {
"type": "string",
},
},
"required": ["name", "favorite_number","favorite_color"]
}
我可以使用这个 JSON 模式来验证我的数据对象是否符合它:
public static boolean isJsonValid(String schemaText, String jsonText) throws ProcessingException, IOException
{
final JsonSchema schemaNode = getSchemaNode(schemaText);
final JsonNode jsonNode = getJsonNode(jsonText);
return isJsonValid(schemaNode, jsonNode);
}
在我的 java 应用程序中,我从 REST API 调用中接收到该对象的相应 AVRO 模式,该模式如下所示:
{
"namespace": "example.avro",
"type": "record",
"name": "Person",
"fields": [
{"name": "name", "type": "string"},
{"name": "favorite_number", "type": ["int", "null"]},
{"name": "favorite_color", "type": ["string", "null"]}
]
}
是否有一种普遍可接受的方式将此类 AVRO 模式转换为 JSON 模式?