Использование Spring Boot 2.1.6.RELEASE. Я получил конечную точку REST следующим образом:
@RequestMapping(method = RequestMethod.POST, produces = "application/json", path = "/test")
public ResponseEntity<Dto2> test(@RequestBody Dto1 dto1)
...
Вызов ее из Почтальона работает нормально и возвращает ожидаемую полезную нагрузку. Однако при вызове с клиента, как показано ниже:
ResponseEntity<Dto2> resp = restTemplate.exchange("/test", HttpMethod.POST, new HttpEntity<>(Dto1, headers), Dto2.class);
вызывает следующее исключение:
org.springframework.http.converter.HttpMessageConversionException:
Type definition error: [simple type, class <package name>Dto2];
nested exception is
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot
construct instance of `<package name>Dto2`,
problem: `java.lang.NullPointerException`
at [Source: (PushbackInputStream); line: 1, column: 2]
В файле журнала отображаются следующие сообщения:
13:48:24.735 [main] DEBUG org.springframework.web.client.RestTemplate - HTTP PUT http://<host>:<port>/<context root>/test
13:48:24.762 [main] DEBUG org.springframework.web.client.RestTemplate - Accept=[application/json, application/*+json]
13:48:24.776 [main] DEBUG org.springframework.web.client.RestTemplate -
Writing [<package name>Dto1@7efaad5a] with org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
13:48:24.886 [main] DEBUG org.springframework.web.client.RestTemplate - Response 200 OK
13:48:24.887 [main] DEBUG org.springframework.web.client.RestTemplate - Reading to [<package name>Dto2]
Cannot construct instance of `<package name>Dto2`, problem: `java.lang.NullPointerException`
[ERROR] Tests run: 5, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 5.42 s
Вот данные:
public class Dto1
{
private Long field1;
private String field2;
...
}
public class Dto2
{
private Dto1 dto1;
private Long field1;
private String field2;
...
}
Кто-нибудь знает, в чем здесь проблема?
Заранее большое спасибо.
С уважением,
Nicolas