有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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) 个答案