I use Gson to serialize / deserialize my pojos and am currently looking for a clean way to tell Gson to parse / infer date attributes as unix-timestamps. Here is my attempt:
Gson gson = new GsonBuilder().setDateFormat("U").create();
Starting with PHP, where "U" is the date format used to parse / output the date as unix-timestamps, when I run my attempt code, I get this RuntimeException:
Unknown character 'U' character
I assume that Gson uses SimpleDateformat under the hood, which does not define the letter "U".
I could write DateTypeAdapterand register it in GsonBuilder, but I am looking for a cleaner way to achieve this. A simple change DateFormatwould be wonderful.
source
share