当使用Jackson的JSON模式模块时,不是序列化完整的图表,我想在遇到我的模型类之一时停止,并使用类名为另一个模式插入$ ref 。你能指导我到jackson-module-jsonSchema源码的正确位置开始修补吗?Jackson:使用引用生成模式
下面是一些代码来说明这个问题:
public static class Zoo {
public String name;
public List<Animal> animals;
}
public static class Animal {
public String species;
}
public static void main(String[] args) throws Exception {
SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
ObjectMapper mapper = objectMapperFactory.getMapper();
mapper.acceptJsonFormatVisitor(mapper.constructType(Zoo.class), visitor);
JsonSchema jsonSchema = visitor.finalSchema();
System.out.println(mapper.writeValueAsString(jsonSchema));
}
输出:
{
"type" : "object",
"properties" : {
"animals" : {
"type" : "array",
"items" : {
"type" : "object",
"properties" : { <---- Animal schema is inlined :-(
"species" : {
"type" : "string"
}
}
}
},
"name" : {
"type" : "string"
}
}
}
所需的输出:
{
"type" : "object",
"properties" : {
"animals" : {
"type" : "array",
"items" : {
"$ref" : "#Animal" <---- Reference to another schema :-)
}
},
"name" : {
"type" : "string"
}
}
}
对我没有效果。仍然生成ReferenceSchema,而不是解析的。 –