Reputation: 491
I am consuming an API through Retrofit2, and I want to parse/transform the response to my model type object. The thing is that the recieved answer in Json is like this:
...
Then, my model object has this structure:
public class ApiTokenResponse {
@SerializedName("data")
@Expose
private JsonArray data;
@SerializedName("id")
@Expose
private int id;
The problem is that I am just focused on receiving the id, not the jsonarray called data, but the only value I receive is the data array, the id is null. Do I have to later iterate the data array and get the id value or is there any way to get it directly?
Thanks
Upvotes: 0
Views: 593
Reputation: 48
Your model structure has a problem. You most make your model like that.
public class Response {
private List<Info> data;
}
And
public class Info {
private int id;
private String created_at;
private String updated_at;
private String deleted_at;
}
Note: if your JSON tag name is the same as your java variable, you can not use @SerializedName
.
Note: if retrofit can't find or pars a @SerializedName
in model make it NULL.
Upvotes: 1