我们希望序列化Java类的模式,以便任何字段或类上出现的所有注释也被序列化到模式中。
我还没有找到能做到这一点的工具。
Avro不处理非字符串映射键,FasterXML也不处理循环引用。而且它们都不会将注释序列化到模式中。
有没有Java JSON (反)序列化程序可以做到这一点?
发布于 2014-04-19 10:54:02
Apache Thrift在大多数语言中支持复杂的映射键,并且对JSON序列化有相当广泛的支持。类型循环(自引用类型等)是最近引入的,还没有在各种语言中发布或实现。也就是说,似乎有一个坚定的承诺,要在短期内将这种能力提高到一个高度的水平。
现在,使用C++开发人员主干时,可以使用以下内容。
struct tree {
1: tree left (cpp.ref="")
2: tree right (cpp.ref="")
}
service simple {
void hello(1: string msg, 2: tree t)
}发布于 2014-07-09 20:59:41
现在,Jackson JSON Schema Module支持循环依赖。下面是一个适用于2.4.1版本的示例:
public class JacksonSchemaCyclic {
public static class Bean {
@JsonPropertyDescription("This is a property description")
public String anExample;
public int anInt;
public Bean aBean;
}
public static void main(String[] args) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
mapper.acceptJsonFormatVisitor(Bean.class, visitor);
JsonSchema jsonSchema = visitor.finalSchema();
System.out.println(mapper
.writerWithDefaultPrettyPrinter().writeValueAsString(jsonSchema));
}
}输出:
{
"type" : "object",
"id" : "urn:jsonschema:stackoverflow:JacksonSchemaCyclic:Bean",
"properties" : {
"aBean" : {
"type" : "object",
"$ref" : "urn:jsonschema:stackoverflow:JacksonSchemaCyclic:Bean"
},
"anInt" : {
"type" : "integer"
},
"anExample" : {
"type" : "string",
"description" : "This is a property description"
}
}
}https://stackoverflow.com/questions/23146816
复制相似问题