To simplify I have json
string with the structure:
{
"route": {
"bus-1": {
"stations": [
],
"geo": [
]
},
"bus-2": {
"stations": [
],
"geo": [
]
}
},
"routesReverse": {
"bus-1": {
"stations": [
],
"geo": [
]
},
"bus-2": {
"stations": [
],
"geo": [
]
}
}
}
I'm trying to parse it using GSON
:
public class MainJson {
@SerializedName("route")
@Expose
public Routes route;
@SerializedName("routesReverse")
@Expose
public Routes routesReverse;
public Routes getRoute() {
return route;
}
public Routes getRoutesReverse() {
return routesReverse;
}
}
I had created all models but and I have a question about this model:
public class Routes {
@SerializedName("bus-1")
@Expose
BusStop busStop1;
@SerializedName("bus-2")
@Expose
BusStop busStop2;
public BusStop getBusStop1() {
return busStop1;
}
public BusStop getBusStop2() {
return busStop2;
}
}
I don't like this approach to create BusStop
object with annotation for each bus-route, I would like to create something like List<BusStop>
because my json
has not only 2 routes.
How to achieve that ?