JavaPOJO到Json模式
我有下面的Json字符串
{
"name": "Mr Xyz"
}
上述JSON的Java模型类如下所示
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"name"
})
public class Test {
@JsonProperty("name")
@JsonPropertyDescription("Non Zero Length String")
@Size(min = 1)
@NotNull
private String name;
Jackson API用于以下测试。类Java对象生成下面的json模式
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Test",
"type": "object",
"additionalProperties": false,
"properties": {
"name": {
"type": "string",
"minLength": 1,
"description": "Non Zero Length String"
}
},
"required": [
"name"
]
}
我的问题是如何更改JavaPOJO对象,使其能够生成如下模式
{
"$id": "test id",
"$schema": "http://json-schema.org/draft-07/schema",
"title": "Test title",
"description": "test description",
"type": "object",
"properties": {
"name": {
"$ref": "#/definitions/d_NonZeroLengthString"
}
},
"definitions": {
"d_NonZeroLengthString": {
"description": "Non Zero Length String",
"type": "string",
"minLength": 1
}
}
}
# 1 楼答案
尝试使用https://github.com/mbknor/mbknor-jackson-jsonSchema, 它创建“$ref”和“definitions”