I am using retrofit to retrieve json object. However, I was wondering if there is an easy way to retrieve nested objects.
Here's my JSON string:
{
"name": "125 8th avenue",
"address": "125 8th avenue, San fran ,CA 09012",
"location": {
"lon": -72.98013329999998,
"lat": 45.7552112
},
"email": "support@email.com",
"primaryContact": {
"firstName": "john",
"lastName": "doe",
"jobTitle": "General Manager, 8th Ave",
"email": "support@email.com",
"photo": "//images.ctfassets.net/qykmdxxsgb04/3EaIeJ29djgo6Exve4Q7xb.jpeg"
}
I am retrieving the name and email as :
@Expose
@SerializedName("name")
private String name;
@Expose
@SerializedName("email")
private String email;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof MyInfo)) return false;
MyInfo that = (MyInfo) o;
if (!name.equals(that.name)) return false;
}
@Override
public int hashCode() {
int result = name.hashCode();
result = 31 * result + email.hashCode();
return result;
}
As you see from JSON, its pretty straightforward to retrieve name and email but not sure how I can easily retrieve primaryContact details(say firstname and lastname) within the same file ? Any ideas?
Thanks in advance