开发者

Enable Jackson to not output the class name when serializing (using Spring MVC)

Is there a way to force Jackson not to put the class name in the Json output? I asked a question that led to this question, but I'm asking what I hope is a more focused question. I'm using Spring MVC while doing this, but I'm not sure how much that matters.

So, instead of


{"NamedSystem":{"name":"Bob Dole","id":"0开发者_开发技巧198b96c-fe18-4aa6-9e61-b5f7149414c2"}}

I want


{"name":"Bob Dole","id":"0198b96c-fe18-4aa6-9e61-b5f7149414c2"}

I might prefer the former, but I don't know how to get Jackson to recognize the class name when deserializing, so if anyone knows that, that would be helpful too.


I found a way to do this with Spring MVC, thanks to http://pascaldimassimo.com/2010/04/13/how-to-return-a-single-json-list-out-of-mappingjacksonjsonview/#comment-4

I had actually been going down that route (changing the way it's serialized by Spring) and had something similar but not quite the same (and which wasn't working), but this does the trick perfectly.


Not sure what to do here, but I think it is Spring that adds that name. Jackson itself would not do it by default. So it is probably more of SpringMVC question.


I think you will have to write a custom serializer that handles your data. This could help you on to the way of achieving that.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜