Retrofit: Not able to format Date type as Query/Field/Header parameter

Created on 27 May 2015  路  2Comments  路  Source: square/retrofit

Trying to use Date type as a Query parameter, the server is expecting a format like "2015-05-26T20:00:26.069Z", but Retrofit sends in format "Tue May 26 19:31:56 EDT 2015" which cause the server paring error.

It's nice to allow customized format of Date in Query/Field/Header. Similar to Gson:
new GsonBuilder().setDateFormat(""yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"")...

Most helpful comment

I think the formatting for Date is worth to implement.

All 2 comments

Per the docs of @Query

Values are converted to strings using String.valueOf(Object) and then URL encoded.

You should either render the Date to a string before calling Retrofit or use a wrapper object whose toString() formats the date in the way that your server expects.

Having an API for controlling the date format is a very specific thing that's not worth its weight. Furthermore, this API would mean that you would have to configure both Retrofit _and_ Gson (if you were using Gson) for them to behave the same.

After version 2.0 we might have argument interceptors which will allow you to control how arguments are converted into their string representation (#816).

I think the formatting for Date is worth to implement.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MetaiR picture MetaiR  路  3Comments

bhagyasri picture bhagyasri  路  3Comments

Ne1c picture Ne1c  路  3Comments

colintheshots picture colintheshots  路  3Comments

zheangrybear picture zheangrybear  路  3Comments