spring mvc not returning json content - error 406

后端 未结 14 1299
温柔的废话
温柔的废话 2020-11-30 05:10

I am using Spring MVC with JSON as specified in Ajax Simplification Spring 3.0 article.

After so many attempts and variations of my code depending on advice found on

14条回答
  •  囚心锁ツ
    2020-11-30 05:33

    As said by axtavt, mvc:annotation-driven and jackson JSON mapper are all that you need. I followed that and got my application to return both JSON and XML strings from the same method without changing any code, provided that there are @XmlRootElement and @XmlElement in the object you are returning from the controller. The difference was in the accept parameter passed in the request or header. To return xml, any normal invocation from the browser will do it, otherwise pass the accept as 'application/xml'. If you want JSON returned, use 'application/json' in the accept parameter in request.

    If you use firefox, you can use tamperdata and change this parameter

提交回复
热议问题