开发者

Why is Jackson wrapping my objects with an extra layer named after the class?

开发者 https://www.devze.com 2023-03-15 15:21 出处:网络
When I serialize public class FOO { int field1; String开发者_如何学编程 field2; } I got the following.

When I serialize

public class FOO {
int field1;
String开发者_如何学编程 field2;
}

I got the following.

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

Can you point me how can I make the output look like this

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


I've figured out how to make it. Actually the problem is that MappingJacksonJsonView has a map So that's why it returns it that way {"FOO":{"field1":0,"field2":"value"}}

But If I configured it that way

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

It will serialize the object itself not the whole map. I hope it will help someone else.

0

精彩评论

暂无评论...
验证码 换一张
取 消