I am fetching a JSON using retrofit 2, which carries object if the key has value else an empty array. ex:
If the key i.e address has values it returns object
{
"student": {
"name": "Some name",
"address": {
"house": "5",
"road": "3"
}
}
}
If the key i.e address does not have any value it returns empty array
{
"student": {
"name": "Some name",
"address": []
}
}
In my POJO class I have made my Address class type to object so that retrofit can parse the JSON.
public class Student {
@SerializedName("name")
@Expose
private String name;
@SerializedName("address")
@Expose
private Object address;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Object getAddress() {
return address;
}
public void setAddress(Object address) {
this.address = address;
}
}
Now how can I check that the address type is object or an array?
I have tried with isArray(), but did not find result.
if(obj.getclass().isArray())
Thanks in advance.