1313
1414package com .bandwidth .sdk ;
1515
16- import com .fasterxml .jackson .databind .util .StdDateFormat ;
1716import com .google .gson .Gson ;
1817import com .google .gson .GsonBuilder ;
1918import com .google .gson .JsonParseException ;
2019import com .google .gson .TypeAdapter ;
20+ import com .google .gson .internal .bind .util .ISO8601Utils ;
2121import com .google .gson .stream .JsonReader ;
2222import com .google .gson .stream .JsonWriter ;
2323import com .google .gson .JsonElement ;
3131import java .lang .reflect .Type ;
3232import java .text .DateFormat ;
3333import java .text .ParseException ;
34+ import java .text .ParsePosition ;
3435import java .time .LocalDate ;
3536import java .time .OffsetDateTime ;
36- import java .time .ZoneId ;
37- import java .time .ZoneOffset ;
3837import java .time .format .DateTimeFormatter ;
3938import java .util .Date ;
4039import java .util .Locale ;
4140import java .util .Map ;
4241import java .util .HashMap ;
43- import java .util .TimeZone ;
4442
4543/*
4644 * A JSON utility class
@@ -57,11 +55,6 @@ public class JSON {
5755 private static LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter ();
5856 private static ByteArrayAdapter byteArrayAdapter = new ByteArrayAdapter ();
5957
60- private static final StdDateFormat sdf = new StdDateFormat ()
61- .withTimeZone (TimeZone .getTimeZone (ZoneId .systemDefault ()))
62- .withColonInTimeZone (true );
63- private static final DateTimeFormatter dtf = DateTimeFormatter .ISO_OFFSET_DATE_TIME ;
64-
6558 @ SuppressWarnings ("unchecked" )
6659 public static GsonBuilder createGson () {
6760 GsonFireBuilder fireBuilder = new GsonFireBuilder ()
@@ -409,7 +402,7 @@ public java.sql.Date read(JsonReader in) throws IOException {
409402 if (dateFormat != null ) {
410403 return new java .sql .Date (dateFormat .parse (date ).getTime ());
411404 }
412- return new java .sql .Date (sdf .parse (date ).getTime ());
405+ return new java .sql .Date (ISO8601Utils .parse (date , new ParsePosition ( 0 ) ).getTime ());
413406 } catch (ParseException e ) {
414407 throw new JsonParseException (e );
415408 }
@@ -419,7 +412,7 @@ public java.sql.Date read(JsonReader in) throws IOException {
419412
420413 /**
421414 * Gson TypeAdapter for java.util.Date type
422- * If the dateFormat is null, DateTimeFormatter will be used.
415+ * If the dateFormat is null, ISO8601Utils will be used.
423416 */
424417 public static class DateTypeAdapter extends TypeAdapter <Date > {
425418
@@ -444,7 +437,7 @@ public void write(JsonWriter out, Date date) throws IOException {
444437 if (dateFormat != null ) {
445438 value = dateFormat .format (date );
446439 } else {
447- value = date . toInstant (). atOffset ( ZoneOffset . UTC ). format (dtf );
440+ value = ISO8601Utils . format (date , true );
448441 }
449442 out .value (value );
450443 }
@@ -463,7 +456,7 @@ public Date read(JsonReader in) throws IOException {
463456 if (dateFormat != null ) {
464457 return dateFormat .parse (date );
465458 }
466- return sdf .parse (date );
459+ return ISO8601Utils .parse (date , new ParsePosition ( 0 ) );
467460 } catch (ParseException e ) {
468461 throw new JsonParseException (e );
469462 }
0 commit comments