6

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.

Community
  • 1
  • 1
AHungerArtist
  • 9,332
  • 17
  • 73
  • 109

3 Answers3

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

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.

AHungerArtist
  • 9,332
  • 17
  • 73
  • 109
2

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.

StaxMan
  • 113,358
  • 34
  • 211
  • 239
  • I wish I had realized that much earlier -- it was my understanding that Jackson/JSON wouldn't want that first element but I wasn't sure. I did finally find a solution online, though. – AHungerArtist Jul 21 '10 at 21:46
  • Ah ok. Yes, it is often hard to figure out which component does what. Spring builds quite a bit of convenience functionality on top of things, which is good but can make troubleshooting trickier. – StaxMan Jul 22 '10 at 18:17
1

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.

Redlab
  • 3,110
  • 19
  • 17