gpt4 book ai didi

java - Pojo 到 Json 架构

转载 作者:行者123 更新时间:2023-12-05 06:59:39 25 4
gpt4 key购买 nike

我有下面的 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;

以下 Test.class Java 对象的 Jackson API 生成以下 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
}
}
}

最佳答案

尝试使用https://github.com/mbknor/mbknor-jackson-jsonSchema ,它创建“$ref”和“定义”

关于java - Pojo 到 Json 架构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64348860/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com