1

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 !

carlo
  • 386
  • 1
  • 8
  • 21
  • 1
    I guess you don't need to define jsonHttpMessageConverter, JacksonObjectMapper etc. in the spring configuration. They are added by default if jackson classes are present in classpath. The 'supports' method of MappingJacksonHttpMessageConverter should not be called if configuration is correct. – Ritesh Jul 05 '11 at 13:12
  • I have deleted the configuration for jsonHttpMessageConverter and JacksonObjectMapper. But now I have this error: The server refused this request because the request entity is in a format not supported by the requested resource for the requested method Any ideas ? – carlo Jul 05 '11 at 13:32
  • Try after removing '@RequestParam' from method. I guess @RequestParam and @RequestBody should not be used together. – Ritesh Jul 05 '11 at 14:18
  • Same problem if I leave @RequestParam. – carlo Jul 05 '11 at 14:34

1 Answers1

0

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.

Community
  • 1
  • 1
AmirHd
  • 10,308
  • 11
  • 41
  • 60