-3

I am getting HTTP error code 406 with following error description:

The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.

My Goal is to get my POJO class in json response. Kindly find my following configurations:

@RequestMapping(value="/testjson",produces="application/json")
    public @ResponseBody Employee testjson () {
        System.err.println("testing json");
        Employee testEmp = new Employee("1", "Ankit", "Agarwal");

        return testEmp;
    }

spring-servlet.xml

<bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/pages/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>
    <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
      <property name="mediaTypes">
        <map>
           <entry key="json" value="application/json" />
           <entry key="xml" value="application/xml" />
           <entry key="rss" value="application/rss+xml" />
        </map>
      </property>
    </bean>
Ankit
  • 425
  • 1
  • 5
  • 21
  • I had added in spring-servlet.xml and i can see json response with POJO class. – Ankit Aug 31 '16 at 04:52
  • I had one doubt. I had removed bean ContentNegotiatingViewResolver in spring-servlet.xml and also removed produces="application/json" on RequestMapping. Still i can see json response on this url. Does anybody knows from where its catching that response will be of type json ? – Ankit Aug 31 '16 at 04:55

1 Answers1

0

try this

@RequestMapping(value="/testjson",produces="application/json",headers = {"Content-type=application/json"})
Eiko
  • 25,601
  • 15
  • 56
  • 71
  • 2
    Please edit with more information. Code-only and "try this" answers are discouraged, because they contain no searchable content, and don't explain why someone should "try this". We make an effort here to be a resource for knowledge. – Brian Tompsett - 汤莱恩 Sep 01 '16 at 14:04
  • My only concern is that i removed produces="application/json" in class. Still i am able to get json response. I wanted to know which part of spring does that. Thanks for your response. – Ankit Sep 02 '16 at 09:45