Retrofit GSON serialize Date from json string into

Gson gson = new GsonBuilder()

RestAdapter restAdapter = new RestAdapter.Builder()
    .setConverter(new GsonConverter.create(gson))

Or the Kotlin equivalent:

val gson = GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create()
RestAdapter restAdapter = Retrofit.Builder()

You can set your customized Gson parser to retrofit. More here: Retrofit Website

Look at Ondreju’s response to see how to implement this in retrofit 2.

Leave a Comment