So to add another POJO you can do this:
private static Gson gson = new GsonBuilder()
.registerTypeAdapter(Model1.class, new GsonDeserializer<Model1>())
.registerTypeAdapter(Model2.class, new GsonDeserializer<Model2>())
//or create a POJO for the names array of Model2
.registerTypeAdapter(Model2.class, new GsonDeserializer<Names>())
Where GsonDeserializer
is a custom serializer that can be defined, like:
public class GsonDeserializer<T> implements JsonDeserializer<T> {
@Override
public T deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject el = json.getAsJsonObject();
return new Gson().fromJson(el, typeOfT);
}
And then in your Retrofit client you just add:
retrofit = new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create(gson))
.build();