Why does Jackson wrap my objects with an extra layer named after the class?

When i serialize

public class FOO {
int field1;
String field2;
}

I got the following.

{"FOO":{"field1":0,"field2":"value"}}

Can you tell me how I can draw a conclusion this way

{"field1":0,"field2":"value"}
+5
source share
1 answer

I figured out how to do this. Actually the problem is that MappingJacksonJsonView has a map. Therefore, why does he return it that way{"FOO":{"field1":0,"field2":"value"}}

But if I set it up that way

<beans:bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
       <beans:property name="extractValueFromSingleKeyModel" value="true" />
</beans:bean>

It serializes the object itself, not the entire map. Hope this helps someone else.

+12
source

All Articles