Retrofit gson converter for nested Json Object with Date property
<p>JSON structure looks like the following:</p>

<pre><code>"blabla": 1234,
"blabla2": "1234",
"object": {
        "property1": "1234",
        "property2": "blablab",
        "property3": "12345",
        "property4": Date object,
    }
}
</code></pre>

<p>Due to this structure, I have implemented a custom deserializer and passed it in the TypeAdapter:</p>

<pre><code>.registerTypeAdapter(Date.class, new DateDeserializer())
                .registerTypeAdapter(GenericNotificationResponse.class, new NotificationDeserializer())
                .setDateFormat("yyyy-MM-dd'T'HH:mm:ss")
                .create();

public class NotificationDeserializer implements JsonDeserializer&lt;GenericNotificationResponse&gt; {
    @Override
    public GenericNotificationResponse deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
        JsonObject content = json.getAsJsonObject();
        GenericNotificationResponse message = new Gson().fromJson(json, typeOfT);
        JsonElement notification = content.get("notification");
        if (message.mType == 1)
            message.mNotification = (new Gson().fromJson(notification, Model1.class));
        else if (message.mType == 2)
            message.mNotification = (new Gson().fromJson(notification, Model2.class));
        return message;
    }
}
</code></pre>

<p>And the deserialization of the inner object goes fine. Until recently, when I changed the model and started receiving a Date object as well, as shown in the JSON structure, the last property. For some reason, it cannot parse it and it throws an error, so it seems like the DateDeserializer that I'm passing in the TypeAdapter is not called due to the these lines:</p>

<pre><code> message.mNotification = (new Gson().fromJson(notification, Model1.class));

message.mNotification = (new Gson().fromJson(notification, Model2.class));
</code></pre>

<p>The DateDeserializer works since I'm using it within other models and it does the trick. Is there any way I can make the deserialization of the date property in the inner json Object? Thank you!</p>