@Data
@Builder
@JsonDeserialize(builder = JacksonTest.JacksonTestBuilder.class)
public class JacksonTest {
private final String id;
private final String name;
private List<String> hobbies;
private List<CustomType> customs;
@JsonPOJOBuilder(withPrefix = "")
public static class JacksonTestBuilder {
}
}
我有json
{"id":"id"}
预期的pojo会有
id: id
name: null
hobbies : empty lists
customs: empty list
如何将空列表/集合反序列化为空集合,而不显式初始化变量。
答案 0 :(得分:0)
使用自定义反序列化器应该可以工作。
看看这个问题:
How to define a generic list deserializer through annotations with Jackson?