启用杰克逊序列化时,不能输出类名(使用Spring MVC) [英] Enable Jackson to not output the class name when serializing (using Spring MVC)

查看:338
本文介绍了启用杰克逊序列化时,不能输出类名(使用Spring MVC)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法迫使杰克逊不要把类名在JSON输出?我问了一个<一个href=\"http://stackoverflow.com/questions/3300144/problem-deserializing-with-jackson-using-jaxb-annotations-in-spring-mvc\">question导致这个问题,但我问什么,我希望是一个更集中的问题。我使用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.

因此​​,代替


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

我想


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

我可能preFER前者,但我不知道怎么去杰克逊承认反序列化时,类名,因此,如果每个人都知道,这将是有益的了。

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.

推荐答案

我找到了一种与Spring MVC的要做到这一点,得益于<一个href=\"http://pascaldimassimo.com/2010/04/13/how-to-return-a-single-json-list-out-of-mappingjacksonjsonview/#comment-4\" rel=\"nofollow\">http://pascaldimassimo.com/2010/04/13/how-to-return-a-single-json-list-out-of-mappingjacksonjsonview/#comment-4

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

我其实一直往下走这条路线(改变它由Spring连载的方式),也有类似的东西,但不完全一样(而这是不工作),但是这确实的伎俩完美。

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.

这篇关于启用杰克逊序列化时,不能输出类名(使用Spring MVC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆