Pojo转Json Schema

3

我有以下的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根据下面的Test.class 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"
    ]
}

我的问题是如何更改我的Java pojo对象,以便它可以生成以下模式

{
    "$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
        }
    }
}

你为什么期望Jackson创建定义? - OneCricketeer
@OneCricketeer 因为即使我的 JSON 消息是正确的,但我无法将其发送到 Kafka 模式注册表 Broker,因为它显示无效模式。 - hello world
这个工具可能会有帮助:http://www.jsonschema2pojo.org/ - DigitShifter
1个回答

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接