Spring MVC POST @RequestBody don't bind to JSON string in the http request

this is my signature of the POST method of my Spring MVC controller

@RequestMapping(value="/createNewGame", method=RequestMethod.POST)
       public ModelAndView createNewGame(@RequestParam(value="phoneNumber") String param,@RequestBody final SampleDTO sampleDTO) {
        Map model2 = new HashMap();
           model2.put("firstname", "Peter");
           model2.put("secondname", "Schmitt");

           return new ModelAndView("jsonView", model2);
     }

instead this is the definition of the SampleDTO class:

public class SampleDTO implements Serializable{

    private String value;

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
}

I'm not able to execute the request for this method. I have this error from the client:

org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.supports(Ljava/lang/Class;)Z

after execute this POST request with RestClient app with these parameters:

http://localhost:8080/SpringExample5/createNewGame.json?phoneNumber=6   (POST)

Content-Type application/json  (Header attribute)

{ "value": "a" }      (Body)

This is also the configuration of Spring in my web app:

<bean name="/gameController.json" 
          class="com.alu.server.games.acquisition.controllers.GameController"/>   


<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />
<bean id="jsonView" class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"/>

<bean id="jsonHttpMessageConverter"
    class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" >
    <property name="objectMapper">
            <ref bean="JacksonObjectMapper" />
       </property>
</bean>

    <bean
    class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="messageConverters">
        <list>
            <ref bean="jsonHttpMessageConverter" />            
        </list>
    </property>
</bean>

<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
    <property name="objectMapper">
         <ref bean="JacksonObjectMapper" />
    </property>
</bean>

<bean id="JacksonObjectMapper" class="org.codehaus.jackson.map.ObjectMapper" />

Someone can help me in order to find the problem? Thanks in advance !


In the setting I used I did specify the Media Type to be "application/json" both in the web service's annotation as well as the XML configuration for json message converter.
Please checkout my FAQ on the matter here for further details.

链接地址: http://www.djcxy.com/p/48452.html

上一篇: Curl不适用于HTTP Post到Spring

下一篇: Spring MVC POST @RequestBody不绑定到http请求中的JSON字符串