英文:
How to display default value in JSON Schema using Jackson
问题
我正在使用Jackson来创建JSON模式。我希望在JSON模式中显示属性及其默认值。我尝试了使用@JsonProperty注解,并配合default属性,但默认值仍未显示在JSON模式中。
我正在使用以下代码生成JSON模式:
ObjectMapper mapper = new ObjectMapper();
JsonSchemaGenerator schemaGen = new JsonSchemaGenerator(mapper);
JsonSchema schema = null;
try {
schema = schemaGen.generateSchema(RootTemplate.class);
System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema));
}
catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
英文:
I am using Jackson to create json schema. I want to display property with their default value in json schema. I tried @JsonProperty annotation with default attribute but still default value is not being display on the json schema.
I am using following code to generate Json Schema:
ObjectMapper mapper = new ObjectMapper();
JsonSchemaGenerator schemaGen = new JsonSchemaGenerator(mapper);
JsonSchema schema = null;
try {
schema = schemaGen.generateSchema(RootTemplate.class);
System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema));
}
catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
专注分享java语言的经验与见解,让所有开发者获益!
评论