通过注释将Java类转换为JSON自定义模式
我目前正在生成Json模式,如下所示:通过注释将Java类转换为JSON自定义模式,java,jackson,annotations,jsonschema,Java,Jackson,Annotations,Jsonschema,我目前正在生成Json模式,如下所示: class Item { public int id; public string name; public string description; } ObjectMapper mapper = new ObjectMapper(); SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); mapper.acceptJsonFormatVisitor(Item.cla
class Item {
public int id;
public string name;
public string description;
}
ObjectMapper mapper = new ObjectMapper();
SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
mapper.acceptJsonFormatVisitor(Item.class, visitor);
JsonSchema schema = visitor.finalSchema();
System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema));
其中打印:
{
"type": "object",
"id": "urn:jsonschema:de:foo:bar:User",
"properties": {
"id": { "type": "integer" },
"name": { "type": "string" },
"description": { "type": "string" }
}
}
现在,我想从Item类的注释中为每种类型添加额外的信息。我希望它提供有关如何显示该字段输入的信息
class User {
public int id;
public string name;
@MyJsonSchemaAnnotation(fieldName = "input", value = "textarea")
public string description;
}
这将给我:
{
"type": "object",
"id": "urn:jsonschema:de:foo:bar:User",
"properties": {
"id": { "type": "integer" },
"name": { "type": "string" },
"description": { "type": "string", "input": "textarea" }
}
}
我认为这类似于@JsonDescription或JSR303注释。我有点不知所措,如果这是可能的话,如果是的话,我必须以何种方式实现它。因此,如果有人能给我一个提示,在哪里看它将不胜感激 该包将java POJO转换为json模式。它有@JsonPropertyDescription
注释,可用于自定义模式
请注意,到目前为止,它只支持json模式的草稿4。该包将java POJO转换为json模式。它有@JsonPropertyDescription
注释,可用于自定义模式
注意,到目前为止,它只支持json模式的草案4