I'm attempting to unmarshall a quite simple JSON string into a Java object. But I'm getting an error when using ObjectMapper to map the String to a Java object.
The error I am getting is the following
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of WebserviceDOInterface
(no Creators, like default constructor, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
at [Source: (String)"[truncated 254 chars]; line: 1, column: 203] (through reference chain: WSDomainObject["webReqDomainObject"])
I'm not quite sure how to cast this to a String due to the polymorphic aspect of the class, is there some annotations that I have to add to my classes or do I just have to set up by object mapper in a different way? Any help would be greatly apprecaited.
Here is the JSON i'm trying to cast:
{
"webReqDomainObject": {
"id": "601942353"
},
"webRespDomainObject": {
"systemException": {
"errorCode": "303",
"errorMessage": "Service error encountered",
"source": "SERVICE",
"httpStatusCode": "500",
"systemException": true
},
"profiles": null
}
}
This is the object that I'm trying to cast the above to.
@JsonIgnoreProperties(
ignoreUnknown = true
)
public class WSDomainObject<WSSReq extends WebserviceDOInterface, WSSResp extends WebserviceDOInterface> {
@JsonProperty("webReqDomainObject")
private WSSReq webReqDomainObject;
@JsonProperty("webRespDomainObject")
private WSSResp webRespDomainObject;
public WSDomainObject() {
}
public WSSReq getWebReqDomainObject() {
return webReqDomainObject;
}
public void setWebReqDomainObject(WSSReq webReqDomainObject) {
this.webReqDomainObject = webReqDomainObject;
}
public WSSResp getWebRespDomainObject() {
return webRespDomainObject;
}
public void setWebRespDomainObject(WSSResp webRespDomainObject) {
this.webRespDomainObject = webRespDomainObject;
}
}
This is all the WebserviceDOInterface is, just a marker interface.
public interface WebserviceDOInterface {
}
This is the instance of the WSSReq
WSReq
@JsonIgnoreProperties(
ignoreUnknown = true
)
public class RetrieveRequestDomainObject implements WebserviceDOInterface {
@JsonProperty("id")
private String id;
public RetrieveRequestDomainObject(String id) {
this.id = id;
}
public LoyaltyAccountRetrieveRequestDomainObject() {
}
public String getId() {
return this.id;
}
public void setId(String id) {
this.id = id;
}
}
This is the instance of the WSResp
@JsonIgnoreProperties(
ignoreUnknown = true
)
public class RetrieveResponseDomainObject extends WebserviceDomainObjectResponse {
@JsonProperty("profiles")
private ProfilesTypeDO profiles;
public RetrieveResponseDomainObject() {
}
public ProfilesTypeDO getProfiles() {
return this.profiles;
}
public void setProfiles(ProfilesTypeDO profiles) {
this.profiles = profiles;
}
}
public abstract class WebserviceDomainObjectResponse implements WebserviceDOInterface {
private SystemException caughtException = new SystemException();
public WebserviceDomainObjectResponse() {
}
public SystemException getSystemException() {
return this.caughtException;
}
public boolean isSystemException() {
return this.caughtException.isSystemException();
}
}