0

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?

colymore
  • 11,776
  • 13
  • 48
  • 90

1 Answers1

0

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.

jmvivo
  • 2,653
  • 1
  • 16
  • 20
  • I have jackson on both apps, the class has the MappingJacksonHttpMessageConverter anotation, and my class have the anotations, need i to convert my user object to json before the request or androidannotations do it self? – colymore Feb 25 '14 at 18:45
  • Thanks for that mini checklist! – eruiz Mar 11 '14 at 08:56