0

I use Spring boot 2 default configuration to deserialize from json to object. Can it deserialize json if it has more key:value pair than java object? Like this:

json:

{
  "id": 2,
  "name": "Jane",
  "age": 21
}

Java class:

public class ClientResponse {
    private Long id;
    private String name;
}

Java object has not age property, but json has.

Does it convert correctly?

qwerty
  • 87
  • 2
  • 8

1 Answers1

0

Yes. Just add the following annotation on your class:

@JsonIgnoreProperties({"age"})
public class ClientResponse {}

If you want to ignore any unknown properties:

@JsonIgnoreProperties(ignoreUnknown=true)

Reference info.

Benoit
  • 5,118
  • 2
  • 24
  • 43