I faced a problem with json serialization with Gson
. So, I access an API using retrofit with dynamic returns as there's inconsistently json field.
The return looks like this:
{
"_id": "5959bace87b42b0012dd32e3",
"user": {
"_id": "58fdaca91ab5920012328669",
"email": "xxx@xxxx.xx",
"fullName": "User full name"
"phonenumber": "+449xxxx",
"profilePicture": ""
}
}
But sometimes, the return would be like this (look at user
field):
{
"_id": "5959bace87b42b0012dd32e3",
"user": "58fdaca91ab5920012328669"
}
This is my POJO
public class Order{
@PrimaryKey
@SerializedName("_id")
@Expose
String id;
@SerializedName("user")
@Expose
User user;
//getter setter
}
Anyone know how to solve this problem?
Thanks