2
2
3
3
package { {invokerPackage} };
4
4
5
- import com.fasterxml.jackson.databind.util.StdDateFormat;
6
5
import com.google.gson.Gson;
7
6
import com.google.gson.GsonBuilder;
8
7
import com.google.gson.JsonParseException;
9
8
import com.google.gson.TypeAdapter;
9
+ import com.google.gson.internal.bind.util.ISO8601Utils;
10
10
import com.google.gson.stream.JsonReader;
11
11
import com.google.gson.stream.JsonWriter;
12
12
import com.google.gson.JsonElement;
@@ -27,16 +27,14 @@ import java.io.StringReader;
27
27
import java.lang.reflect.Type;
28
28
import java.text.DateFormat;
29
29
import java.text.ParseException;
30
+ import java.text.ParsePosition;
30
31
import java.time.LocalDate;
31
32
import java.time.OffsetDateTime;
32
- import java.time.ZoneId;
33
- import java.time.ZoneOffset;
34
33
import java.time.format.DateTimeFormatter;
35
34
import java.util.Date;
36
35
import java.util.Locale;
37
36
import java.util.Map;
38
37
import java.util.HashMap;
39
- import java.util.TimeZone;
40
38
41
39
/*
42
40
* A JSON utility class
@@ -59,11 +57,6 @@ public class JSON {
59
57
{ {/jsr310} }
60
58
private static ByteArrayAdapter byteArrayAdapter = new ByteArrayAdapter();
61
59
62
- private static final StdDateFormat sdf = new StdDateFormat()
63
- .withTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault()))
64
- .withColonInTimeZone(true);
65
- private static final DateTimeFormatter dtf = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
66
-
67
60
@SuppressWarnings("unchecked")
68
61
public static GsonBuilder createGson() {
69
62
GsonFireBuilder fireBuilder = new GsonFireBuilder()
@@ -466,7 +459,7 @@ public class JSON {
466
459
if (dateFormat != null) {
467
460
return new java.sql.Date(dateFormat.parse(date).getTime());
468
461
}
469
- return new java.sql.Date(sdf .parse(date).getTime());
462
+ return new java.sql.Date(ISO8601Utils .parse(date, new ParsePosition(0) ).getTime());
470
463
} catch (ParseException e) {
471
464
throw new JsonParseException(e);
472
465
}
@@ -476,7 +469,7 @@ public class JSON {
476
469
477
470
/**
478
471
* Gson TypeAdapter for java.util.Date type
479
- * If the dateFormat is null, DateTimeFormatter will be used.
472
+ * If the dateFormat is null, ISO8601Utils will be used.
480
473
*/
481
474
public static class DateTypeAdapter extends TypeAdapter<Date > {
482
475
@@ -501,7 +494,7 @@ public class JSON {
501
494
if (dateFormat != null) {
502
495
value = dateFormat.format(date);
503
496
} else {
504
- value = date.toInstant().atOffset(ZoneOffset.UTC). format(dtf );
497
+ value = ISO8601Utils. format(date, true );
505
498
}
506
499
out.value(value);
507
500
}
@@ -520,7 +513,7 @@ public class JSON {
520
513
if (dateFormat != null) {
521
514
return dateFormat.parse(date);
522
515
}
523
- return sdf .parse(date);
516
+ return ISO8601Utils .parse(date, new ParsePosition(0) );
524
517
} catch (ParseException e) {
525
518
throw new JsonParseException(e);
526
519
}
0 commit comments