【发布时间】:2019-06-10 09:56:47
【问题描述】:
我目前正在像这样生成我的 Json 架构:
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 或JSR 303 Annotations。如果这是可能的,我有点迷茫,如果可以,我必须以哪种方式实现它。因此,如果有人能给我提示在哪里看它,将不胜感激!
【问题讨论】:
标签: java jackson annotations jsonschema