java自定义序列化程序和Jackson模式
我有以下两门课:
public class MyChild
{
@JsonProperty
public int x;
}
public class MyTest
{
public void MyChild() {}
@JsonSerialize(using = MapValueSerializer.class)
private Map<String, MyChild> childs = new LinkedHashMap<>();
}
我希望childs序列化为MyChild
数组,而不是映射(仅值)。因此,我使用以下自定义序列化程序:
public class MapValueSerializer extends StdSerializer<Map<String, ?>>
{
protected MapValueSerializer()
{
this(null);
}
protected MapValueSerializer(Class<Map<String, ?>> t)
{
super(t);
}
@Override
public void serialize(Map<String, ?> value, JsonGenerator gen, SerializerProvider provider) throws IOException
{
provider.defaultSerializeValue(value.values(), gen);
}
}
当我现在使用JsonSchemaGenerator
从MyTest
生成一个模式时,我得到了以下结果:
{
"type" : "object",
"id" : "urn:jsonschema:com:myclasses:MyTest",
"properties" : {
"childs" : {
"type" : "any"
}
}
}
但childs不应该是“any”类型,而应该是“object”类型。如果删除序列化程序,则类型为“object”。我是否需要添加一些东西来让模式生成器知道该类型
共 (0) 个答案