Suppress wrapper object when serializing Java object into JSON using Jackson

后端 未结 5 2307
忘掉有多难
忘掉有多难 2021-02-14 23:45

I have a web service that returns a list as JSON. It uses Jackson to map a List of Java POJOs into JSON. The problem is that the JSON representation has a wrapper object around

5条回答
  •  深忆病人
    2021-02-15 00:17

    I stumbled upon this question while trying to solve the same problem, but was not using this with a @ResponseBody method, but was still encountering the "wrapper" in my serialized JSON. My solution was to add @JsonAnyGetter to the method/field, and then the wrapper would disappear from the JSON.

    Apparently this is a known Jackson bug/workaround: http://jira.codehaus.org/browse/JACKSON-765.

提交回复
热议问题