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

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

问题描述

有没有办法强制 Jackson 不要将类名放在 Json 输出中?我问了一个 问题 导致了这个问题,但我问的是我希望是一个更集中的问题.我在执行此操作时使用 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"}

我可能更喜欢前者,但我不知道如何在反序列化时让 Jackson 识别出类名,所以如果有人知道这一点,那也会有帮助.

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.

推荐答案

感谢 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.

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

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