Announcement Announcement Module
Collapse
No announcement yet.
Getting null values when using Jackson mapper to map @RequestBody params Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Getting null values when using Jackson mapper to map @RequestBody params

    I've recently updated to Spring 3.1 M2, and this problem just started happening. It is working fine in M1. I'm posting JSON from the client into a @Controller method, and the binding parameter object is just getting null values. I'm posting this JSON:

    Code:
    { "username":"admin", "password":"password" }
    Here is the controller method:

    Code:
    @RequestMapping(value="/login", method=RequestMethod.POST)
    @ResponseBody
    public ApiResponse login(@RequestBody LoginCredentials credentials, HttpServletRequest req) { }
    The LoginCredentials class is a simple class with getters and setters for username and password. And here is a sample of my spring XML file:

    Code:
    <bean id="annotationMethodHandlerAdapter1" class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
            <property name="order" value="0" />
            <property name="messageConverters">
                <list>
                    <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
                </list>
            </property>
    </bean>
    Like I said, this is working just fine in 3.1 M1, the post data is properly binding to the LoginCredentials class. But with M2, I just get null values in the class. Any help would be greatly appreciated.

  • #2
    Any help on this would be greatly appreciated, since we are trying to aggressively keep pace with each 3.1.0 release, so our product is ready for the final release. Thanks!

    Comment


    • #3
      I was told that the Spring community is really helpful and responsive. I'm surprised that I haven't had a single suggestion yet from anyone. I've done some more digging, and found that if I don't include <mvc:annotation-driven /> in my spring configuration file, then the json is binding in just fine. Can anyone explain this, and tell me what issues I might run into by not including this? Thanks in advance for your help.

      --Eric

      Comment

      Working...
      X