Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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":"0198b96c-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.

like image 960
AHungerArtist Avatar asked Jul 21 '10 19:07

AHungerArtist


1 Answers

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.

like image 90
AHungerArtist Avatar answered Nov 14 '22 23:11

AHungerArtist