收集包装作为JSON列表?

时间:2015-09-21 12:07:26

标签: jackson

我需要在DTO中包含List<Something>(例如Wrapper),以便某些自定义注释按预期工作。我最终得到了这个:

public class Wrapper {
    private List<Something> list;

    @CustomAnnotationsHere
    public List<Something> getList() { ... }

    public void setList(List<Something> list) { ... }
}

但是,这使得Jackson将Wrapper对象序列化/反序列化为

{
  "list": [...]
}
其中,恕我直言,过于冗长且不必要的复杂。有没有办法让杰克逊序列化/反序列化这个Wrapper对象作为列表(list字段的值)?

我发誓我曾经遇到过基于注释的方法来实现这一目标,但目前我无法回想起去哪里。

1 个答案:

答案 0 :(得分:2)

@JsonValue添加到字段以进行序列化,并将单参数构造函数添加到反序列化中吗?