The deserialization is failing after the update.
I updated my micro-service from Spring 1.5.10.RELEASE
to Spring 2.0.3.RELEASE
and also updated the lombok
from 1.16.14
to 1.18.0
and jackson-datatype-jsr310
from 2.9.4
to 2.9.6
.
The JSON string -
{"heading":"Validation failed","detail":"field must not be null"}
The Class -
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class ErrorDetail {
private final String heading;
private final String detail;
private String type;
}
Method call -
ErrorDetail errorDetail = asObject(jsonString, ErrorDetail.class);
The method used to deserialize -
import com.fasterxml.jackson.databind.ObjectMapper;
// more imports and class defination.
private static <T> T asObject(final String str, Class<T> clazz) {
try {
return new ObjectMapper().readValue(str, clazz);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Error -
java.lang.RuntimeException: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `com.foo.bar.ErrorDetail` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: (String)"{"heading":"Validation failed","detail":"field must not be null"}"; line: 1, column: 2]