0

I am Using soring MVC 3.2.1.I am using a controller which should return a json, I have included jackson jars too.But json is not returned.It give error The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers ().

@RequestMapping(value = "/search.json", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    protected @ResponseBody
    LoginDto searchDeals(@ModelAttribute Deal deal) {
        /*
         * DealDao dealdao = new DealDao(); List<Deal> deals =
         * dealdao.search(deal);
         */
        return new LoginDto("sdadas", "asdasdas");
    }

config

<!--
    <bean name="/UploadEmployeeServlet.do"
    class="com.etnow.UploadEmployeeServlet" />
-->
<context:component-scan base-package="com.etnow.*" />
<mvc:annotation-driven
    content-negotiation-manager="contentNegotiationManager" />
<bean id="contentNegotiationManager"
    class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
    <property name="favorPathExtension" value="false" />
    <property name="favorParameter" value="false" />
    <property name="ignoreAcceptHeader" value="false" />
    <property name="mediaTypes">
        <value>
            json=application/json
        </value><!--
    -->
    </property>
</bean>

<mvc:view-controller path="/one.do" view-name="SignUp" />
<bean id="viewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
        <value>/WEB-INF/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>

Please help It works fine in 3.0 without setting contentNogotiation Manager but not in the latest version of spring MVC

1 Answer 1

1

It sounds like you need to send "Accept= application/json" in your header when making the http request.

You can also check that you can get json and that your jars are installed correctly by creating an ObjectMapper object and checking canSerialize(class) on your return type.

How are you posting data?

Removing "produces = "application/json;charset=UTF-8" " might also do the trick, but if you want to include that line you'll need to include the accepts header in your http request.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.