• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring MVC/REST controller: how to convert java to JSON

 
Siegfried Heintze
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following controller is working because I can single step thru it:

I use this command line:


However, I get this error from curl:


OK, so what do I have to do to fix this? Somewhere it needs to know how to generate JSON and it is not doing it.
Can someone guide me?
Thanks
Siegfried
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Siegfried

Have you tried adding produces = "application/json" to your RequestMapping annotation?
 
Siegfried Heintze
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I tried your suggestion:


I'm still getting

"The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers."
Thanks
Siegfried
 
H Paul
Ranch Hand
Posts: 471
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Have a check on this line and its implication.
To me, the server is saying I'm expecting a header tag Content-Type=text/xml or application/json.

Did the client send a header tag

Content-type: text/xml or application/json

 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Siegfried, what version of Spring are you using?
 
udaykiranreddy desam
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai just configure ContentNegotiatingViewResolver in your context and add .json to your request

cool


or just add @ResponeBody in your controller
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic