I am using genson 1.4 for JSON processing in my REST implementation , JSON Inheritance is not working while using genson .please find the sample code structure below.
This is my BaseObject
This is my BaseObject
public class SynBaseObject implements Serializable
{
private Long status;
//GettersAndSetters
}
This is my Child Class
public class PhoneNumber extends SynBaseObject
{
private String countryCode;
private String areaCode;
private String localNumber;
//GettersAndSetters
}
This is my Response Object
public class ResponseObject implements Serializable
{
private Integer errorCode;
private String errorMessage;
private Long primaryKey;
private SynBaseObject baseClass;
public ResponseObject()
{
}
public SynBaseObject getBaseObject()
{
return baseClass;
}
public void setBaseObject(SynBaseObject baseClass)
{
this.baseClass = baseClass;
}
public Integer getErrorCode()
{
return errorCode;
}
public void setErrorCode(Integer errorCode)
{
this.errorCode = errorCode;
}
}
This is the GENSON JSON Output:
{"baseObject":{"status":null},"errorCode":null,"errorMessage":null,"primaryKey":null}
CountryCode
,areaCode
and localNumber
is missing in JSON,only the base class is processed .Tried the same from code like this
Genson genson = new Genson();
PhoneNumber number = new PhoneNumber();
number.setCountryCode("2");
number.setAreaCode("3");
number.setLocalNumber("9645");
ResponseObject responseObject = new ResponseObject();
responseObject.setBaseObject(number);
String serialize = genson.serialize(responseObject);
System.out.println(serialize);
Output was the same like in the rest service.