杰克逊 - 如何从输出JSON中解开根

时间:2014-07-09 11:13:22

标签: json serialization jaxb jackson

我正在使用以下映射器

ObjectMapper mapper = new ObjectMapper ();
mapper.configure(Feature.WRAP_ROOT_VALUE, true);
AnnotationIntrospector primary = new JaxbAnnotationIntrospector();
AnnotationIntrospector secondary = new JacksonAnnotationIntrospector();
AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary);
mapper.setAnnotationIntrospector(pair);

将以下类序列化为JSON

public class MyList {
    @JsonProperty("samples")
    List<Module> sampleList;

    public List<Module> getSampleList() {
        return sampleList;
    }

    public void setSampleList(List<Sample> sampleList) {
        this.sampleList = sampleList;
    }
}

但我得到以下输出:

{"MyList ":{"samples":[ ... ]}}

但我不想要这个MyList。我期待着:

"samples":[...]

如果只明确指定了根目录,我怎么能告诉杰克逊呢?

0 个答案:

没有答案