0

Every time I call my REST API sending a JSON through PUT, for instance, and there is some different property on it, I got 400 (Bad Request) as a result.

Is there any way to configure spring-mvc to ignore no existent properties when JSON and my Class do not perfectly match?

Here is a sample of a method on my controller:

======

@Transactional
@RequestMapping(method=RequestMethod.PUT, value="/include",
    consumes=MediaType.APPLICATION_JSON_VALUE, 
    produces={MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_XML_VALUE })

public @ResponseBody ResponseEntity<Client> 
    inserirClienteSemRedeSocial(@RequestBody Client client) {

    clientDAO.insert(client);

    return new ResponseEntity<Client>(client, HttpStatus.OK);
}
beaumondo
  • 4,862
  • 7
  • 29
  • 42
  • I found the solution here http://stackoverflow.com/questions/14343477/how-do-you-globally-set-jackson-to-ignore-unknown-properties-within-spring – Francisco Júnior Aug 06 '13 at 20:38

1 Answers1

0

you can add to your Pojo:

@JsonIgnoreProperties(ignoreUnknown=true)

which will ignore unknown fields

javadoc

Community
  • 1
  • 1
Udy
  • 2,492
  • 4
  • 23
  • 33
  • Unfortunately no, I'd already tried it. I found the solution here http://stackoverflow.com/questions/14343477/how-do-you-globally-set-jackson-to-ignore-unknown-properties-within-spring – Francisco Júnior Aug 06 '13 at 20:37