I'm trying to map the response of an API to my object:
class Person {
private Long id;
private String firstname;
private String lastname;
public Person(Long id, String firstname, String lastname)
...
and my api call looks like:
RestTemplate restTemplate = new RestTemplate();
Person person = restTemplate.getForObject("http://xxx/getPerson", Person.class);
Which returns a json that looks like:
{
"id": 1,
"firstname": "first",
"lastname": "last"
}
Unfortunately I'm getting the following error:
Type definition error: [simple type, class xxx.Person]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `xxx.Person` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)\n at [Source: (PushbackInputStream); line: 4, column: 5]
Any idea why? I have a constructor in my class so I'm not too sure why this is throwing an error. Thanks!