包括来自jackson json序列化的集合类的属性

时间:2013-05-12 01:26:46

标签: java json jackson

我正在使用杰克逊来序列化我的pojo。通常,我有一个集合类。在这种情况下,我在集合类上有一些需要序列化的其他属性。例如,出于演示目的:

@JsonTypeInfo(use=JsonTypeInfo.Id.NAME, include=JsonTypeInfo.As.WRAPPER_OBJECT)
public class Messages implements List<String> {
    @JsonProperty
    private String info = "hello";

    @JsonProperty
    private ArrayList<String> messages = new ArrayList<String>();
}

这序列化为: { "Messages": [ "a", "b", "c" ] }

我希望将其序列化为: { "info": "hello", "messages": [ "a", "b", "c" ] }

有什么方法可以让杰克逊以我想要的方式将其序列化?

0 个答案:

没有答案
相关问题