13
13
14
14
package org .openapitools .client ;
15
15
16
- import com .fasterxml .jackson .databind .util .StdDateFormat ;
17
16
import com .google .gson .Gson ;
18
17
import com .google .gson .GsonBuilder ;
19
18
import com .google .gson .JsonParseException ;
20
19
import com .google .gson .TypeAdapter ;
20
+ import com .google .gson .internal .bind .util .ISO8601Utils ;
21
21
import com .google .gson .stream .JsonReader ;
22
22
import com .google .gson .stream .JsonWriter ;
23
23
import com .google .gson .JsonElement ;
31
31
import java .lang .reflect .Type ;
32
32
import java .text .DateFormat ;
33
33
import java .text .ParseException ;
34
+ import java .text .ParsePosition ;
34
35
import java .time .LocalDate ;
35
36
import java .time .OffsetDateTime ;
36
- import java .time .ZoneId ;
37
- import java .time .ZoneOffset ;
38
37
import java .time .format .DateTimeFormatter ;
39
38
import java .util .Date ;
40
39
import java .util .Locale ;
41
40
import java .util .Map ;
42
41
import java .util .HashMap ;
43
- import java .util .TimeZone ;
44
42
45
43
/*
46
44
* A JSON utility class
@@ -57,11 +55,6 @@ public class JSON {
57
55
private static LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter ();
58
56
private static ByteArrayAdapter byteArrayAdapter = new ByteArrayAdapter ();
59
57
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
-
65
58
@ SuppressWarnings ("unchecked" )
66
59
public static GsonBuilder createGson () {
67
60
GsonFireBuilder fireBuilder = new GsonFireBuilder ()
@@ -338,7 +331,7 @@ public java.sql.Date read(JsonReader in) throws IOException {
338
331
if (dateFormat != null ) {
339
332
return new java .sql .Date (dateFormat .parse (date ).getTime ());
340
333
}
341
- return new java .sql .Date (sdf .parse (date ).getTime ());
334
+ return new java .sql .Date (ISO8601Utils .parse (date , new ParsePosition ( 0 ) ).getTime ());
342
335
} catch (ParseException e ) {
343
336
throw new JsonParseException (e );
344
337
}
@@ -348,7 +341,7 @@ public java.sql.Date read(JsonReader in) throws IOException {
348
341
349
342
/**
350
343
* Gson TypeAdapter for java.util.Date type
351
- * If the dateFormat is null, DateTimeFormatter will be used.
344
+ * If the dateFormat is null, ISO8601Utils will be used.
352
345
*/
353
346
public static class DateTypeAdapter extends TypeAdapter <Date > {
354
347
@@ -373,7 +366,7 @@ public void write(JsonWriter out, Date date) throws IOException {
373
366
if (dateFormat != null ) {
374
367
value = dateFormat .format (date );
375
368
} else {
376
- value = date . toInstant (). atOffset ( ZoneOffset . UTC ). format (dtf );
369
+ value = ISO8601Utils . format (date , true );
377
370
}
378
371
out .value (value );
379
372
}
@@ -392,7 +385,7 @@ public Date read(JsonReader in) throws IOException {
392
385
if (dateFormat != null ) {
393
386
return dateFormat .parse (date );
394
387
}
395
- return sdf .parse (date );
388
+ return ISO8601Utils .parse (date , new ParsePosition ( 0 ) );
396
389
} catch (ParseException e ) {
397
390
throw new JsonParseException (e );
398
391
}
0 commit comments