如何使用Jackson在JSON Schema中显示默认值

huangapple 未分类评论45阅读模式
英文:

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();
		}

huangapple
  • 本文由 发表于 2020年4月9日 23:28:56
  • 转载请务必保留本文链接:https://java.coder-hub.com/61124672.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定