【发布时间】:2019-10-25 19:38:01
【问题描述】:
我打算将我的POJOs 转换为JSON Schema。
在现有的POJOs 中,我们有来自codehaus 包的注释:
@JsonProperty("address") 其中对应的导入是:
import org.codehaus.jackson.annotate.JsonProperty;
我不能使用codehaus api 来生成架构,因为我们有一个递归的JSON 结构,我得到StackOverflowError。
所以,我尝试使用fasterxml 的jackson-module-jsonschema API 来做到这一点,效果很好。
我得到的示例输出:
"Registration" : {
"type" : "object",
"id" : "urn:jsonschema:com:xyz.abc.Address",
}
我有两个要求:
除了“type”和“id”,我还想要一个description属性。我可以添加
@JsonPropertyDescription属性,这会起作用,但是每个属性都会有一个来自codehaus的注释和另一个来自fasterxml包的注释。codehaus中是否有可用于此目的的等效注解?有没有办法在“id”属性中只使用非限定类名(只有“地址”,即没有限定的对象路径“xyz.abc.Address”并且没有“urn:jsonschema” ) ?
使用fasterxml 生成模式的代码:
ObjectMapper mapper = new ObjectMapper();
JsonSchemaGenerator schemaGen = new JsonSchemaGenerator(mapper);
JsonSchema schema = schemaGen.generateSchema(DashboardDef.class);
String generatedJsonSchema = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema);
【问题讨论】:
-
您的问题解决了吗?下面的答案有帮助吗?
标签: java json jackson jsonschema fasterxml