I am getting an exception when running an integration test with gradle.
The exception I'm getting is:
com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of AbstractCommonDetails: abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
The Summary class has the following annotations on the details I am trying to deserialize:
@Data
public class Summary {
@JsonTypeInfo(use = NAME, include = PROPERTY, property = "@type")
@JsonSubTypes({
@JsonSubTypes.Type(value = CardDetails.class, name = "CARD")
})
private AbstractCommonDetails details;
}
AbstractCommonDetails looks like this:
@Getter
@Setter
public abstract class AbstractCommonDetails {
private Long id;
public abstract String getPaymentMethod();
}
And the CardDetails has @JsonTypeName("CARD")
and @Data
annotations and the implementation of getPaymentMethod
method.
ObjectMapper configuration and deserializing is done as follows:
new ObjectMapper().findAndRegisterModules().readValue(IOUtils.toString(inputStream, "UTF-8"), Summary.class);
And sample json:
{
"details":{
"@type":"CARD",
"amount":"10.00"
}
Weird thing is - running the integration test as a Junit test succeeds but when running the same integration test with gradlew test
command it fails with the exception mentioned before. What could be the cause?