I'm having a hard time using the inheritance on AutoValue
. I have an API which gives the details of a transaction. Some of the fields are present on all types of transactions, but the details are not. Details is specific for each type of transaction.
transaction type 1 json response:
{
"status": "Processing",
"date": "2018-24-1",
"specific_1": "abc",
"specific_2": "xyz"
}
transaction type 2 json response:
{
"status": "Cancelled",
"date": "2018-23-1",
"specific_3": "def",
"specific_4": "ghi"
}
Without AutoValue
, I'll just have to create a Parent Class
that has status
and date
and extend it to specific object with the specific details
fields.
Parent Class:
public class Parent {
@SerializedName("status")
private String status;
@SerializedName("date")
private String date;
//getter setters...
}
First Child Class:
public class FirstChild extends Parent {
@SerializedName("specific_1")
private String specific1;
@SerializedName("specific_2")
private String specific2;
//getter setters...
}
Second Child Class:
public class SecondChild extends Parent {
@SerializedName("specific_3")
private String specific3;
@SerializedName("specific_4")
private String specific4;
//getter setters...
}
Both child will inherit the status
and date
without specifying it on each object. My problem is that AutoValue
does not support this. What can be the workaround without declaring all of the generic fields on each object?