【发布时间】:2014-08-22 08:19:45
【问题描述】:
我正在尝试在我的项目中从 pojos 自动生成 JsonSchema:代码如下所示:
ObjectMapper mapper = new ObjectMapper();
SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
mapper.acceptJsonFormatVisitor(clazz, visitor);
JsonSchema jsonSchema = visitor.finalSchema();
String schemaString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonSchema);
当 clazz 被这样定义时:
public class ZKBean
{
public String anExample;
public int anInt;
}
I end up with this:
{
"type" : "object",
"id" : "urn:jsonschema:com:emc:dpad:util:ZKBean",
"properties" : {
"anInt" : {
"type" : "integer"
},
"anExample" : {
"type" : "string"
}
}
}
这一切都很棒。我想要做的是将“描述”键添加到架构中,这样我就有了如下所示的内容:
{
"type" : "object",
"id" : "urn:jsonschema:com:emc:dpad:util:ZKBean",
"properties" : {
"anInt" : {
"type" : "integer",
"description" : "Represents the number of foos in the system"
},
"anExample" : {
"type" : "string",
"description" : "Some descriptive description goes here"
}
}
}
我以为我可以在我的 ZKBean 类中的字段上添加一些注释,但是经过半天的尝试,我还没有找到。这是要走的路吗?还是我需要对我的访客做点什么?
谢谢, 杰西
【问题讨论】:
标签: java json jackson jsonschema