I am having below 2 JSON, one for login and another one for order
{
"head": {
"requestCode": "code"
},
"body": {
"reqId": "xyz",
"userName": "xyz",
"passwd": "xyz",
}
}
{
"head": {
"requestCode": "code"
},
"body": {
"reqId": "xyz",
"orderId": "xyz"
}
}
I am trying to write java pojo where the head and refId of body are common for each json but other content of body.
something like the below pojo. Now problem is GSon cannot parse and build objects based on nested parameterized types. Is there any better way to implement it? Not JSON structure will not change.
POJO
public class Base<T extends Body> {
@SerializedName("head")
@Expose
public Head head;
@SerializedName("body")
@Expose
private T body;
}
public class Body {
@SerializedName("clientCode")
@Expose
private String clientCode;
}
public class Head {
@SerializedName("requestCode")
@Expose
public String requestCode;
}
public class Login extends Body {
@SerializedName("userName")
@Expose
public String userName;
@SerializedName("passwd")
@Expose
public String passed;
}
public class Order extends Body {
@SerializedName("orderId")
@Expose
String orderId;
}