I am trying to write a JUNIT for my serialization class.Version i am using for jackson is jackson-databind-2.10.2 My Concrete class extends and abstract class. When i am running my JUNIT i am getting an exception, Missing type id when trying to resolve subtype of [simple type,ReshipInfo]: missing type id property 'type' Below is my JSON to serialize. What i am missing. Please help.
{
"orderId" : "12345",
"orderDocumentType" : "SALES"
}
JUNIT Call
InputStream is = this.getClass().getClassLoader().getResourceAsStream("samples/response.json");
String control = IOUtils.toString(is, Charsets.UTF_8);
ReshipInfo reshipInfo = objectMapper.readValue(control, ReshipInfo.class);
Concrete Class
public class ReshipInfo extends AbstractRequest {
private Integer returnGracePeriod;
public ReshipInfo() {
}
public ReshipInfo(Builder builder) {
super(builder.orderDocumentType);
returnGracePeriod = builder.returnGracePeriod;
}
}
Abstract Class
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.EXISTING_PROPERTY,
property = "type",
visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = ReshipInfo.class, name = "SALES")
})
public abstract class AbstractRequest {
@JsonProperty(value = "type")
private OrderDocumentType orderDocumentType;
}
I am using an abstract class (in your case - AbstractRequest) while config SetupContext of Jackson. Like: context.setMixInAnnotations(ReshipInfo.class, AbstractRequest.class)
So my entity extends ReshipInfo as abstract, and ReshipInfo does not extend AbstractRequest.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.