1010import java .net .URL ;
1111import java .net .URLEncoder ;
1212import java .net .URLStreamHandler ;
13+ import java .text .DateFormat ;
14+ import java .text .ParseException ;
15+ import java .util .Date ;
1316import java .util .HashMap ;
1417import java .util .List ;
18+ import java .util .Locale ;
1519import java .util .Map ;
1620import java .util .Scanner ;
21+ import java .util .TimeZone ;
1722
18- import net .billforward .amendments .Amendment ;
1923import net .billforward .exception .APIConnectionException ;
2024import net .billforward .exception .APIException ;
2125import net .billforward .exception .AuthenticationException ;
2226import net .billforward .exception .CardException ;
2327import net .billforward .exception .InvalidRequestException ;
2428import net .billforward .gson .typeadapters .RuntimeTypeAdapterFactory ;
2529import net .billforward .model .APIResponse ;
30+ import net .billforward .model .amendments .Amendment ;
2631import net .billforward .model .gateways .APIConfiguration ;
2732import net .billforward .model .gateways .GatewayTypeMapping ;
2833import net .billforward .model .notifications .Notification ;
3136import com .google .gson .FieldNamingPolicy ;
3237import com .google .gson .Gson ;
3338import com .google .gson .GsonBuilder ;
39+ import com .google .gson .JsonDeserializationContext ;
40+ import com .google .gson .JsonDeserializer ;
41+ import com .google .gson .JsonElement ;
42+ import com .google .gson .JsonParseException ;
43+ import com .google .gson .JsonPrimitive ;
44+ import com .google .gson .JsonSerializationContext ;
45+ import com .google .gson .JsonSerializer ;
3446import com .google .gson .annotations .Expose ;
3547
3648@ SuppressWarnings ({ "unchecked" , "rawtypes" })
@@ -116,8 +128,10 @@ public String getApiUrl() {
116128 }
117129
118130 //2014-09-12T03:00:17Z
131+ //.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
132+
119133 GSON = new GsonBuilder ()
120- .setDateFormat ( "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" )
134+ .registerTypeAdapter ( Date . class , new DateTypeAdapter () )
121135 .excludeFieldsWithoutExposeAnnotation ()
122136 .registerTypeAdapterFactory (apiConfigAdapter )
123137 .registerTypeAdapterFactory (amendmentConfigAdapter )
@@ -126,7 +140,28 @@ public String getApiUrl() {
126140 .create ();
127141 }
128142
129-
143+ private static class DateTypeAdapter implements JsonSerializer <Date >, JsonDeserializer <Date > {
144+ private final DateFormat dateFormat ;
145+
146+ private DateTypeAdapter () {
147+ dateFormat = new java .text .SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss'Z'" , Locale .US );
148+ dateFormat .setTimeZone (TimeZone .getTimeZone ("UTC" ));
149+ }
150+
151+ public Date deserialize (JsonElement jsonElement , Type arg1 , JsonDeserializationContext arg2 ) throws JsonParseException {
152+ Date date = null ;
153+ try {
154+ date = dateFormat .parse (jsonElement .getAsString ());
155+ } catch (ParseException e ) {
156+ }
157+ return date ;
158+ }
159+
160+ public JsonElement serialize (Date date , Type arg1 , JsonSerializationContext arg2 ) {
161+ String dateFormatAsString = dateFormat .format (date );
162+ return new JsonPrimitive (dateFormatAsString );
163+ }
164+ }
130165
131166 /*
132167 * Set this property to override your environment's default
0 commit comments