【发布时间】:2020-06-14 20:35:17
【问题描述】:
我有一个使用 Azul 的 2.2.4 版和 Zulu Java 11.0.5 的 Spring Boot 应用程序。它正在访问部署在 Payara Web 服务器(版本 5.194)上的 REST Web 服务。
我正在使用以下 DTO:
public class IdDTO extends BasicResponseDTO {
private long id;
public IdDTO(long id) {
this.id = id;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}
和
public class BasicResponseDTO implements Serializable {
private String errorCode;
public BasicResponseDTO() {
this.setErrorCode(null);
}
public String getErrorCode() {
return errorCode;
}
public void setErrorCode(String errorCode) {
this.errorCode = errorCode;
}
}
我调用了一个 REST Web 服务,我看到我从 Postman 收到(正确)以下响应:
{
"errorCode": null,
"id": 3534016
}
但是,当我检索响应时,出现以下异常:
class org.springframework.web.client.RestClientException/Error while extracting response for type [class com.dto.IdDTO] and content type [application/json;charset=UTF-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot construct instance of `com.dto.IdDTO` (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `com.dto.IdDTO` (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: (PushbackInputStream); line: 1, column: 2]
有没有人知道为什么应用程序无法将接收到的 JSON 映射到对象?
附: 1) 我还有其他扩展 BasicResponseDTO 的 DTO,并且反序列化对它们很好。
附: 2) 服务端和客户端的类定义是一样的。
【问题讨论】:
标签: json spring-boot rest java-11 payara