简体   繁体   中英

Spring RestService with android client send object for RequestBody

i have a rest service in spring with tomcat server, with this declaration:

public @ResponseBody User addUser(@RequestBody User user) {

I need to call from an android client to it, im using androidanotations library with Spring Rest Library. My code is:

    @Post("/addUser")
    @Accept(MediaType.APPLICATION_JSON)
    public User addUser(User user);

But when i do the request, server response me 400, bad request.

The User class is serializable, what is wrong?

Check this list:

  1. Your has got Jackson2 dependency on your server application
  2. Your has got Jackson2 dependency on your android application
  3. Your android client has the MappingJacksonHttpMessageConverter registered.
  4. Your User class has any special attribute which needs to be annotated with a Jackson2 annotation (date fields, Maps, List).
  5. Your Controller @RequestMapping is correctly annotated.

To trace what is really sent to server you can use a Request filter like this .

Good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM