I have a particular situation where I am retrieving a list of Objects which have unique Ids as their keys, and they also have nested objects which also have their own unique ids.
I am using GSON
to create pojos but when creating model classes for these objects I would need to serialize all unique key values, this is not a good solution.
I have attached an image to give you a better idea of what I am talking about:
I want GSON
to create a list of NestedObject1
which will it self contain a list of NestedObject2
. The problem is that the key value is unique for each type of NestedObject
I was thinking of doing something like so:
Objects.java
public class Objects {
@SerializedName("Objects")
private List<NestedObject1> mNestedObjects1;
public List<NestedObject1> getNestedObjects1() {
return mNestedObjects1;
}
}
NestedObjects1.java
public class NestedObject1 {
@SerializedName("WHAT-TO-PUT-HERE?")
private String mId;
public String getId() {
return mId;
}
@SerializedName("WHAT-TO-PUT-HERE?")
private List<NestedObject2> mNestedObjects2;
public List<NestedObject2> getNestedObjects2() {
return mNestedObjects2;
}
}
NestedObject2
public class NestedObject2 {
// Same deal here?
}
Any suggestions on how to tackle this?
EDIT: Sample JSON OUTPUT
"Objects" : {
"-JrEvneZHQV73jxKu0-U" : {
"-JrEvoBeZaysRRttNGP-" : {
"started" : true
},
"-JrEvqaNyTHhjRIMGR-r" : {
"started" : true
}
},
"-JrF0_yWy_NmrMROB3qp" : {
"-JrF0lWRsa5KmU6SnC7Z" : {
"started" : true
},
"-JrF1txLoFd2w4wN8Q4n" : {
"started" : true
},
"-JrF2skHdMmT9WN3wKVS" : {
"started" : true
}
},
"-JrF3XSkpvo2WMzF1osb" : {
"-JrF3ZYwyxUz0RDooVna" : {
"started" : true
},
"-JrF4D-cesLhqbbzdfT1" : {
"started" : true
},
"-JrF5GufdDqFGjw8aYRB" : {
"started" : true
}
},
}