diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/RFC3339DateFormat.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/RFC3339DateFormat.java index fa2752bd6f8d..9a089de40c36 100644 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/RFC3339DateFormat.java +++ b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/RFC3339DateFormat.java @@ -17,23 +17,35 @@ package org.openapitools.codegen.online; -import com.fasterxml.jackson.databind.util.ISO8601DateFormat; -import com.fasterxml.jackson.databind.util.ISO8601Utils; +import com.fasterxml.jackson.databind.util.StdDateFormat; +import java.text.DateFormat; import java.text.FieldPosition; +import java.text.ParsePosition; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; import java.util.Date; +import java.util.TimeZone; - -public class RFC3339DateFormat extends ISO8601DateFormat { +public class RFC3339DateFormat extends DateFormat { private static final long serialVersionUID = 1L; + private static final DateTimeFormatter dtf = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + private static final StdDateFormat sdf = new StdDateFormat() + .withTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault())) + .withColonInTimeZone(true); - // Same as ISO8601DateFormat but serializing milliseconds. @Override public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) { - String value = ISO8601Utils.format(date, true); + String value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); toAppendTo.append(value); return toAppendTo; } -} \ No newline at end of file + @Override + public Date parse(String source, ParsePosition pos) { + return sdf.parse(source, pos); + } + +} diff --git a/modules/openapi-generator/src/main/resources/Java/JSON.mustache b/modules/openapi-generator/src/main/resources/Java/JSON.mustache index 1d0a8138787b..0b4651d79282 100644 --- a/modules/openapi-generator/src/main/resources/Java/JSON.mustache +++ b/modules/openapi-generator/src/main/resources/Java/JSON.mustache @@ -2,11 +2,11 @@ package {{invokerPackage}}; +import com.fasterxml.jackson.databind.util.StdDateFormat; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; import com.google.gson.TypeAdapter; -import com.google.gson.internal.bind.util.ISO8601Utils; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import com.google.gson.JsonElement; @@ -33,11 +33,14 @@ import java.text.ParseException; import java.text.ParsePosition; import java.time.LocalDate; import java.time.OffsetDateTime; +import java.time.ZoneOffset; +import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.Locale; import java.util.Map; import java.util.HashMap; +import java.util.TimeZone; public class JSON { private Gson gson; @@ -54,6 +57,11 @@ public class JSON { {{/jsr310}} private ByteArrayAdapter byteArrayAdapter = new ByteArrayAdapter(); + private static final StdDateFormat sdf = new StdDateFormat() + .withTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault())) + .withColonInTimeZone(true); + private static final DateTimeFormatter dtf = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + @SuppressWarnings("unchecked") public static GsonBuilder createGson() { GsonFireBuilder fireBuilder = new GsonFireBuilder() @@ -461,7 +469,7 @@ public class JSON { if (dateFormat != null) { return new java.sql.Date(dateFormat.parse(date).getTime()); } - return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); + return new java.sql.Date(sdf.parse(date).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -471,7 +479,7 @@ public class JSON { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, ISO8601Utils will be used. + * If the dateFormat is null, DateTimeFormatter will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -496,7 +504,7 @@ public class JSON { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = ISO8601Utils.format(date, true); + value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); } out.value(value); } @@ -515,7 +523,7 @@ public class JSON { if (dateFormat != null) { return dateFormat.parse(date); } - return ISO8601Utils.parse(date, new ParsePosition(0)); + return sdf.parse(date); } catch (ParseException e) { throw new JsonParseException(e); } diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/JSON.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/JSON.mustache index d6883b98231f..4ab99a19c9a9 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/JSON.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/JSON.mustache @@ -2,11 +2,11 @@ package {{invokerPackage}}; +import com.fasterxml.jackson.databind.util.StdDateFormat; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; import com.google.gson.TypeAdapter; -import com.google.gson.internal.bind.util.ISO8601Utils; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import com.google.gson.JsonElement; @@ -27,14 +27,16 @@ import java.io.StringReader; import java.lang.reflect.Type; import java.text.DateFormat; import java.text.ParseException; -import java.text.ParsePosition; import java.time.LocalDate; import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.Locale; import java.util.Map; import java.util.HashMap; +import java.util.TimeZone; /* * A JSON utility class @@ -57,6 +59,11 @@ public class JSON { {{/jsr310}} private static ByteArrayAdapter byteArrayAdapter = new ByteArrayAdapter(); + private static final StdDateFormat sdf = new StdDateFormat() + .withTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault())) + .withColonInTimeZone(true); + private static final DateTimeFormatter dtf = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + @SuppressWarnings("unchecked") public static GsonBuilder createGson() { GsonFireBuilder fireBuilder = new GsonFireBuilder() @@ -459,7 +466,7 @@ public class JSON { if (dateFormat != null) { return new java.sql.Date(dateFormat.parse(date).getTime()); } - return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); + return new java.sql.Date(sdf.parse(date).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -469,7 +476,7 @@ public class JSON { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, ISO8601Utils will be used. + * If the dateFormat is null, DateTimeFormatter will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -494,7 +501,7 @@ public class JSON { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = ISO8601Utils.format(date, true); + value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); } out.value(value); } @@ -513,7 +520,7 @@ public class JSON { if (dateFormat != null) { return dateFormat.parse(date); } - return ISO8601Utils.parse(date, new ParsePosition(0)); + return sdf.parse(date); } catch (ParseException e) { throw new JsonParseException(e); } diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/rest-assured/pom.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/rest-assured/pom.mustache index 4d96d46027cf..cab00e2887fe 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/rest-assured/pom.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/rest-assured/pom.mustache @@ -271,6 +271,11 @@ ${gson-fire-version} {{/gson}} + + com.fasterxml.jackson.core + jackson-databind + ${jackson-databind-version} + {{#jackson}} @@ -281,10 +286,6 @@ com.fasterxml.jackson.core jackson-annotations - - com.fasterxml.jackson.core - jackson-databind - org.openapitools jackson-databind-nullable @@ -351,9 +352,9 @@ {{#joda}} 2.10.5 {{/joda}} + 2.15.2 {{#jackson}} 2.15.2 - 2.15.2 0.2.6 {{/jackson}} {{#useJakartaEe}} diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/retrofit2/JSON.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/retrofit2/JSON.mustache index 2ff8b1cb739c..2d791d4ff588 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/retrofit2/JSON.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/retrofit2/JSON.mustache @@ -2,11 +2,11 @@ package {{invokerPackage}}; +import com.fasterxml.jackson.databind.util.StdDateFormat; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; import com.google.gson.TypeAdapter; -import com.google.gson.internal.bind.util.ISO8601Utils; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import com.google.gson.JsonElement; @@ -32,11 +32,14 @@ import java.text.ParseException; import java.text.ParsePosition; import java.time.LocalDate; import java.time.OffsetDateTime; +import java.time.ZoneOffset; +import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.Locale; import java.util.Map; import java.util.HashMap; +import java.util.TimeZone; public class JSON { private Gson gson; @@ -51,6 +54,11 @@ public class JSON { private LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter(); {{/jsr310}} + private static final StdDateFormat sdf = new StdDateFormat() + .withTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault())) + .withColonInTimeZone(true); + private static final DateTimeFormatter dtf = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + public static GsonBuilder createGson() { GsonFireBuilder fireBuilder = new GsonFireBuilder() {{#models}}{{#model}}{{#discriminator}} .registerTypeSelector({{classname}}.class, new TypeSelector() { @@ -362,7 +370,7 @@ public class JSON { if (dateFormat != null) { return new java.sql.Date(dateFormat.parse(date).getTime()); } - return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); + return new java.sql.Date(sdf.parse(date).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -372,7 +380,7 @@ public class JSON { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, ISO8601Utils will be used. + * If the dateFormat is null, DateTimeFormatter will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -398,7 +406,7 @@ public class JSON { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = ISO8601Utils.format(date, true); + value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); } out.value(value); } @@ -417,7 +425,7 @@ public class JSON { if (dateFormat != null) { return dateFormat.parse(date); } - return ISO8601Utils.parse(date, new ParsePosition(0)); + return sdf.parse(date); } catch (ParseException e) { throw new JsonParseException(e); } diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/retrofit2/pom.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/retrofit2/pom.mustache index 8b2a61fcfaec..2bf85c7d242d 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/retrofit2/pom.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/retrofit2/pom.mustache @@ -211,6 +211,11 @@ swagger-annotations ${swagger-annotations-version} + + com.fasterxml.jackson.core + jackson-databind + ${jackson-databind-version} + com.google.code.findbugs @@ -296,11 +301,6 @@ jackson-annotations ${jackson-version} - - com.fasterxml.jackson.core - jackson-databind - ${jackson-databind-version} - {{#openApiNullable}} org.openapitools @@ -362,9 +362,9 @@ ${java.version} 1.9.0 1.6.3 + 2.15.2 {{#usePlayWS}} 2.15.2 - 2.15.2 2.6.7 {{#openApiNullable}} 0.2.6 diff --git a/samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java b/samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java index 65e1121927d0..ad091f5cb543 100644 --- a/samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java +++ b/samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java @@ -13,11 +13,11 @@ package org.openapitools.client; +import com.fasterxml.jackson.databind.util.StdDateFormat; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; import com.google.gson.TypeAdapter; -import com.google.gson.internal.bind.util.ISO8601Utils; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import com.google.gson.JsonElement; @@ -31,14 +31,16 @@ import java.lang.reflect.Type; import java.text.DateFormat; import java.text.ParseException; -import java.text.ParsePosition; import java.time.LocalDate; import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.Locale; import java.util.Map; import java.util.HashMap; +import java.util.TimeZone; /* * A JSON utility class @@ -55,6 +57,11 @@ public class JSON { private static LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter(); private static ByteArrayAdapter byteArrayAdapter = new ByteArrayAdapter(); + private static final StdDateFormat sdf = new StdDateFormat() + .withTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault())) + .withColonInTimeZone(true); + private static final DateTimeFormatter dtf = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + @SuppressWarnings("unchecked") public static GsonBuilder createGson() { GsonFireBuilder fireBuilder = new GsonFireBuilder() @@ -334,7 +341,7 @@ public java.sql.Date read(JsonReader in) throws IOException { if (dateFormat != null) { return new java.sql.Date(dateFormat.parse(date).getTime()); } - return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); + return new java.sql.Date(sdf.parse(date).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -344,7 +351,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, ISO8601Utils will be used. + * If the dateFormat is null, DateTimeFormatter will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -369,7 +376,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = ISO8601Utils.format(date, true); + value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); } out.value(value); } @@ -388,7 +395,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return ISO8601Utils.parse(date, new ParsePosition(0)); + return sdf.parse(date); } catch (ParseException e) { throw new JsonParseException(e); } diff --git a/samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/JSON.java b/samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/JSON.java index 3fc3f4c62307..dfe971b780f6 100644 --- a/samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/JSON.java +++ b/samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/JSON.java @@ -13,11 +13,11 @@ package org.openapitools.client; +import com.fasterxml.jackson.databind.util.StdDateFormat; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; import com.google.gson.TypeAdapter; -import com.google.gson.internal.bind.util.ISO8601Utils; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import com.google.gson.JsonElement; @@ -31,14 +31,16 @@ import java.lang.reflect.Type; import java.text.DateFormat; import java.text.ParseException; -import java.text.ParsePosition; import java.time.LocalDate; import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.Locale; import java.util.Map; import java.util.HashMap; +import java.util.TimeZone; /* * A JSON utility class @@ -55,6 +57,11 @@ public class JSON { private static LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter(); private static ByteArrayAdapter byteArrayAdapter = new ByteArrayAdapter(); + private static final StdDateFormat sdf = new StdDateFormat() + .withTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault())) + .withColonInTimeZone(true); + private static final DateTimeFormatter dtf = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + @SuppressWarnings("unchecked") public static GsonBuilder createGson() { GsonFireBuilder fireBuilder = new GsonFireBuilder() @@ -326,7 +333,7 @@ public java.sql.Date read(JsonReader in) throws IOException { if (dateFormat != null) { return new java.sql.Date(dateFormat.parse(date).getTime()); } - return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); + return new java.sql.Date(sdf.parse(date).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -336,7 +343,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, ISO8601Utils will be used. + * If the dateFormat is null, DateTimeFormatter will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -361,7 +368,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = ISO8601Utils.format(date, true); + value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); } out.value(value); } @@ -380,7 +387,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return ISO8601Utils.parse(date, new ParsePosition(0)); + return sdf.parse(date); } catch (ParseException e) { throw new JsonParseException(e); } diff --git a/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/JSON.java b/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/JSON.java index 417a0011024a..dc02eac223b2 100644 --- a/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/JSON.java +++ b/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/JSON.java @@ -13,11 +13,11 @@ package org.openapitools.client; +import com.fasterxml.jackson.databind.util.StdDateFormat; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; import com.google.gson.TypeAdapter; -import com.google.gson.internal.bind.util.ISO8601Utils; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import com.google.gson.JsonElement; @@ -31,14 +31,16 @@ import java.lang.reflect.Type; import java.text.DateFormat; import java.text.ParseException; -import java.text.ParsePosition; import java.time.LocalDate; import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.Locale; import java.util.Map; import java.util.HashMap; +import java.util.TimeZone; /* * A JSON utility class @@ -55,6 +57,11 @@ public class JSON { private static LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter(); private static ByteArrayAdapter byteArrayAdapter = new ByteArrayAdapter(); + private static final StdDateFormat sdf = new StdDateFormat() + .withTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault())) + .withColonInTimeZone(true); + private static final DateTimeFormatter dtf = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + @SuppressWarnings("unchecked") public static GsonBuilder createGson() { GsonFireBuilder fireBuilder = new GsonFireBuilder() @@ -327,7 +334,7 @@ public java.sql.Date read(JsonReader in) throws IOException { if (dateFormat != null) { return new java.sql.Date(dateFormat.parse(date).getTime()); } - return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); + return new java.sql.Date(sdf.parse(date).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -337,7 +344,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, ISO8601Utils will be used. + * If the dateFormat is null, DateTimeFormatter will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -362,7 +369,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = ISO8601Utils.format(date, true); + value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); } out.value(value); } @@ -381,7 +388,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return ISO8601Utils.parse(date, new ParsePosition(0)); + return sdf.parse(date); } catch (ParseException e) { throw new JsonParseException(e); } diff --git a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/JSON.java b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/JSON.java index 6791d767d970..abc0d4b8fd9f 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/JSON.java +++ b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/JSON.java @@ -13,11 +13,11 @@ package org.openapitools.client; +import com.fasterxml.jackson.databind.util.StdDateFormat; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; import com.google.gson.TypeAdapter; -import com.google.gson.internal.bind.util.ISO8601Utils; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import com.google.gson.JsonElement; @@ -31,14 +31,16 @@ import java.lang.reflect.Type; import java.text.DateFormat; import java.text.ParseException; -import java.text.ParsePosition; import java.time.LocalDate; import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.Locale; import java.util.Map; import java.util.HashMap; +import java.util.TimeZone; /* * A JSON utility class @@ -55,6 +57,11 @@ public class JSON { private static LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter(); private static ByteArrayAdapter byteArrayAdapter = new ByteArrayAdapter(); + private static final StdDateFormat sdf = new StdDateFormat() + .withTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault())) + .withColonInTimeZone(true); + private static final DateTimeFormatter dtf = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + @SuppressWarnings("unchecked") public static GsonBuilder createGson() { GsonFireBuilder fireBuilder = new GsonFireBuilder() @@ -364,7 +371,7 @@ public java.sql.Date read(JsonReader in) throws IOException { if (dateFormat != null) { return new java.sql.Date(dateFormat.parse(date).getTime()); } - return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); + return new java.sql.Date(sdf.parse(date).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -374,7 +381,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, ISO8601Utils will be used. + * If the dateFormat is null, DateTimeFormatter will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -399,7 +406,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = ISO8601Utils.format(date, true); + value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); } out.value(value); } @@ -418,7 +425,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return ISO8601Utils.parse(date, new ParsePosition(0)); + return sdf.parse(date); } catch (ParseException e) { throw new JsonParseException(e); } diff --git a/samples/client/petstore/java/okhttp-gson-awsv4signature/src/main/java/org/openapitools/client/JSON.java b/samples/client/petstore/java/okhttp-gson-awsv4signature/src/main/java/org/openapitools/client/JSON.java index e069227577cc..87cf7eba1013 100644 --- a/samples/client/petstore/java/okhttp-gson-awsv4signature/src/main/java/org/openapitools/client/JSON.java +++ b/samples/client/petstore/java/okhttp-gson-awsv4signature/src/main/java/org/openapitools/client/JSON.java @@ -13,11 +13,11 @@ package org.openapitools.client; +import com.fasterxml.jackson.databind.util.StdDateFormat; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; import com.google.gson.TypeAdapter; -import com.google.gson.internal.bind.util.ISO8601Utils; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import com.google.gson.JsonElement; @@ -31,14 +31,16 @@ import java.lang.reflect.Type; import java.text.DateFormat; import java.text.ParseException; -import java.text.ParsePosition; import java.time.LocalDate; import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.Locale; import java.util.Map; import java.util.HashMap; +import java.util.TimeZone; /* * A JSON utility class @@ -55,6 +57,11 @@ public class JSON { private static LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter(); private static ByteArrayAdapter byteArrayAdapter = new ByteArrayAdapter(); + private static final StdDateFormat sdf = new StdDateFormat() + .withTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault())) + .withColonInTimeZone(true); + private static final DateTimeFormatter dtf = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + @SuppressWarnings("unchecked") public static GsonBuilder createGson() { GsonFireBuilder fireBuilder = new GsonFireBuilder() @@ -331,7 +338,7 @@ public java.sql.Date read(JsonReader in) throws IOException { if (dateFormat != null) { return new java.sql.Date(dateFormat.parse(date).getTime()); } - return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); + return new java.sql.Date(sdf.parse(date).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -341,7 +348,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, ISO8601Utils will be used. + * If the dateFormat is null, DateTimeFormatter will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -366,7 +373,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = ISO8601Utils.format(date, true); + value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); } out.value(value); } @@ -385,7 +392,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return ISO8601Utils.parse(date, new ParsePosition(0)); + return sdf.parse(date); } catch (ParseException e) { throw new JsonParseException(e); } diff --git a/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/main/java/org/openapitools/client/JSON.java b/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/main/java/org/openapitools/client/JSON.java index 3f5a7126f4d3..d30a32b2d785 100644 --- a/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/main/java/org/openapitools/client/JSON.java +++ b/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/main/java/org/openapitools/client/JSON.java @@ -13,11 +13,11 @@ package org.openapitools.client; +import com.fasterxml.jackson.databind.util.StdDateFormat; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; import com.google.gson.TypeAdapter; -import com.google.gson.internal.bind.util.ISO8601Utils; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import com.google.gson.JsonElement; @@ -31,14 +31,16 @@ import java.lang.reflect.Type; import java.text.DateFormat; import java.text.ParseException; -import java.text.ParsePosition; import java.time.LocalDate; import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.Locale; import java.util.Map; import java.util.HashMap; +import java.util.TimeZone; /* * A JSON utility class @@ -55,6 +57,11 @@ public class JSON { private static LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter(); private static ByteArrayAdapter byteArrayAdapter = new ByteArrayAdapter(); + private static final StdDateFormat sdf = new StdDateFormat() + .withTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault())) + .withColonInTimeZone(true); + private static final DateTimeFormatter dtf = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + @SuppressWarnings("unchecked") public static GsonBuilder createGson() { GsonFireBuilder fireBuilder = new GsonFireBuilder() @@ -406,7 +413,7 @@ public java.sql.Date read(JsonReader in) throws IOException { if (dateFormat != null) { return new java.sql.Date(dateFormat.parse(date).getTime()); } - return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); + return new java.sql.Date(sdf.parse(date).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -416,7 +423,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, ISO8601Utils will be used. + * If the dateFormat is null, DateTimeFormatter will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -441,7 +448,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = ISO8601Utils.format(date, true); + value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); } out.value(value); } @@ -460,7 +467,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return ISO8601Utils.parse(date, new ParsePosition(0)); + return sdf.parse(date); } catch (ParseException e) { throw new JsonParseException(e); } diff --git a/samples/client/petstore/java/okhttp-gson-group-parameter/src/main/java/org/openapitools/client/JSON.java b/samples/client/petstore/java/okhttp-gson-group-parameter/src/main/java/org/openapitools/client/JSON.java index e069227577cc..87cf7eba1013 100644 --- a/samples/client/petstore/java/okhttp-gson-group-parameter/src/main/java/org/openapitools/client/JSON.java +++ b/samples/client/petstore/java/okhttp-gson-group-parameter/src/main/java/org/openapitools/client/JSON.java @@ -13,11 +13,11 @@ package org.openapitools.client; +import com.fasterxml.jackson.databind.util.StdDateFormat; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; import com.google.gson.TypeAdapter; -import com.google.gson.internal.bind.util.ISO8601Utils; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import com.google.gson.JsonElement; @@ -31,14 +31,16 @@ import java.lang.reflect.Type; import java.text.DateFormat; import java.text.ParseException; -import java.text.ParsePosition; import java.time.LocalDate; import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.Locale; import java.util.Map; import java.util.HashMap; +import java.util.TimeZone; /* * A JSON utility class @@ -55,6 +57,11 @@ public class JSON { private static LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter(); private static ByteArrayAdapter byteArrayAdapter = new ByteArrayAdapter(); + private static final StdDateFormat sdf = new StdDateFormat() + .withTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault())) + .withColonInTimeZone(true); + private static final DateTimeFormatter dtf = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + @SuppressWarnings("unchecked") public static GsonBuilder createGson() { GsonFireBuilder fireBuilder = new GsonFireBuilder() @@ -331,7 +338,7 @@ public java.sql.Date read(JsonReader in) throws IOException { if (dateFormat != null) { return new java.sql.Date(dateFormat.parse(date).getTime()); } - return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); + return new java.sql.Date(sdf.parse(date).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -341,7 +348,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, ISO8601Utils will be used. + * If the dateFormat is null, DateTimeFormatter will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -366,7 +373,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = ISO8601Utils.format(date, true); + value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); } out.value(value); } @@ -385,7 +392,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return ISO8601Utils.parse(date, new ParsePosition(0)); + return sdf.parse(date); } catch (ParseException e) { throw new JsonParseException(e); } diff --git a/samples/client/petstore/java/okhttp-gson-nullable-required/src/main/java/org/openapitools/client/JSON.java b/samples/client/petstore/java/okhttp-gson-nullable-required/src/main/java/org/openapitools/client/JSON.java index 4fd5aa31f9d5..d377df7d2829 100644 --- a/samples/client/petstore/java/okhttp-gson-nullable-required/src/main/java/org/openapitools/client/JSON.java +++ b/samples/client/petstore/java/okhttp-gson-nullable-required/src/main/java/org/openapitools/client/JSON.java @@ -13,11 +13,11 @@ package org.openapitools.client; +import com.fasterxml.jackson.databind.util.StdDateFormat; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; import com.google.gson.TypeAdapter; -import com.google.gson.internal.bind.util.ISO8601Utils; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import com.google.gson.JsonElement; @@ -31,14 +31,16 @@ import java.lang.reflect.Type; import java.text.DateFormat; import java.text.ParseException; -import java.text.ParsePosition; import java.time.LocalDate; import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.Locale; import java.util.Map; import java.util.HashMap; +import java.util.TimeZone; /* * A JSON utility class @@ -55,6 +57,11 @@ public class JSON { private static LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter(); private static ByteArrayAdapter byteArrayAdapter = new ByteArrayAdapter(); + private static final StdDateFormat sdf = new StdDateFormat() + .withTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault())) + .withColonInTimeZone(true); + private static final DateTimeFormatter dtf = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + @SuppressWarnings("unchecked") public static GsonBuilder createGson() { GsonFireBuilder fireBuilder = new GsonFireBuilder() @@ -333,7 +340,7 @@ public java.sql.Date read(JsonReader in) throws IOException { if (dateFormat != null) { return new java.sql.Date(dateFormat.parse(date).getTime()); } - return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); + return new java.sql.Date(sdf.parse(date).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -343,7 +350,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, ISO8601Utils will be used. + * If the dateFormat is null, DateTimeFormatter will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -368,7 +375,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = ISO8601Utils.format(date, true); + value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); } out.value(value); } @@ -387,7 +394,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return ISO8601Utils.parse(date, new ParsePosition(0)); + return sdf.parse(date); } catch (ParseException e) { throw new JsonParseException(e); } diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/JSON.java b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/JSON.java index 3f5a7126f4d3..d30a32b2d785 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/JSON.java +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/JSON.java @@ -13,11 +13,11 @@ package org.openapitools.client; +import com.fasterxml.jackson.databind.util.StdDateFormat; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; import com.google.gson.TypeAdapter; -import com.google.gson.internal.bind.util.ISO8601Utils; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import com.google.gson.JsonElement; @@ -31,14 +31,16 @@ import java.lang.reflect.Type; import java.text.DateFormat; import java.text.ParseException; -import java.text.ParsePosition; import java.time.LocalDate; import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.Locale; import java.util.Map; import java.util.HashMap; +import java.util.TimeZone; /* * A JSON utility class @@ -55,6 +57,11 @@ public class JSON { private static LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter(); private static ByteArrayAdapter byteArrayAdapter = new ByteArrayAdapter(); + private static final StdDateFormat sdf = new StdDateFormat() + .withTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault())) + .withColonInTimeZone(true); + private static final DateTimeFormatter dtf = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + @SuppressWarnings("unchecked") public static GsonBuilder createGson() { GsonFireBuilder fireBuilder = new GsonFireBuilder() @@ -406,7 +413,7 @@ public java.sql.Date read(JsonReader in) throws IOException { if (dateFormat != null) { return new java.sql.Date(dateFormat.parse(date).getTime()); } - return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); + return new java.sql.Date(sdf.parse(date).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -416,7 +423,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, ISO8601Utils will be used. + * If the dateFormat is null, DateTimeFormatter will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -441,7 +448,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = ISO8601Utils.format(date, true); + value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); } out.value(value); } @@ -460,7 +467,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return ISO8601Utils.parse(date, new ParsePosition(0)); + return sdf.parse(date); } catch (ParseException e) { throw new JsonParseException(e); } diff --git a/samples/client/petstore/java/okhttp-gson-swagger1/src/main/java/org/openapitools/client/JSON.java b/samples/client/petstore/java/okhttp-gson-swagger1/src/main/java/org/openapitools/client/JSON.java index e069227577cc..87cf7eba1013 100644 --- a/samples/client/petstore/java/okhttp-gson-swagger1/src/main/java/org/openapitools/client/JSON.java +++ b/samples/client/petstore/java/okhttp-gson-swagger1/src/main/java/org/openapitools/client/JSON.java @@ -13,11 +13,11 @@ package org.openapitools.client; +import com.fasterxml.jackson.databind.util.StdDateFormat; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; import com.google.gson.TypeAdapter; -import com.google.gson.internal.bind.util.ISO8601Utils; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import com.google.gson.JsonElement; @@ -31,14 +31,16 @@ import java.lang.reflect.Type; import java.text.DateFormat; import java.text.ParseException; -import java.text.ParsePosition; import java.time.LocalDate; import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.Locale; import java.util.Map; import java.util.HashMap; +import java.util.TimeZone; /* * A JSON utility class @@ -55,6 +57,11 @@ public class JSON { private static LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter(); private static ByteArrayAdapter byteArrayAdapter = new ByteArrayAdapter(); + private static final StdDateFormat sdf = new StdDateFormat() + .withTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault())) + .withColonInTimeZone(true); + private static final DateTimeFormatter dtf = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + @SuppressWarnings("unchecked") public static GsonBuilder createGson() { GsonFireBuilder fireBuilder = new GsonFireBuilder() @@ -331,7 +338,7 @@ public java.sql.Date read(JsonReader in) throws IOException { if (dateFormat != null) { return new java.sql.Date(dateFormat.parse(date).getTime()); } - return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); + return new java.sql.Date(sdf.parse(date).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -341,7 +348,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, ISO8601Utils will be used. + * If the dateFormat is null, DateTimeFormatter will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -366,7 +373,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = ISO8601Utils.format(date, true); + value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); } out.value(value); } @@ -385,7 +392,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return ISO8601Utils.parse(date, new ParsePosition(0)); + return sdf.parse(date); } catch (ParseException e) { throw new JsonParseException(e); } diff --git a/samples/client/petstore/java/okhttp-gson-swagger2/src/main/java/org/openapitools/client/JSON.java b/samples/client/petstore/java/okhttp-gson-swagger2/src/main/java/org/openapitools/client/JSON.java index e069227577cc..87cf7eba1013 100644 --- a/samples/client/petstore/java/okhttp-gson-swagger2/src/main/java/org/openapitools/client/JSON.java +++ b/samples/client/petstore/java/okhttp-gson-swagger2/src/main/java/org/openapitools/client/JSON.java @@ -13,11 +13,11 @@ package org.openapitools.client; +import com.fasterxml.jackson.databind.util.StdDateFormat; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; import com.google.gson.TypeAdapter; -import com.google.gson.internal.bind.util.ISO8601Utils; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import com.google.gson.JsonElement; @@ -31,14 +31,16 @@ import java.lang.reflect.Type; import java.text.DateFormat; import java.text.ParseException; -import java.text.ParsePosition; import java.time.LocalDate; import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.Locale; import java.util.Map; import java.util.HashMap; +import java.util.TimeZone; /* * A JSON utility class @@ -55,6 +57,11 @@ public class JSON { private static LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter(); private static ByteArrayAdapter byteArrayAdapter = new ByteArrayAdapter(); + private static final StdDateFormat sdf = new StdDateFormat() + .withTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault())) + .withColonInTimeZone(true); + private static final DateTimeFormatter dtf = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + @SuppressWarnings("unchecked") public static GsonBuilder createGson() { GsonFireBuilder fireBuilder = new GsonFireBuilder() @@ -331,7 +338,7 @@ public java.sql.Date read(JsonReader in) throws IOException { if (dateFormat != null) { return new java.sql.Date(dateFormat.parse(date).getTime()); } - return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); + return new java.sql.Date(sdf.parse(date).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -341,7 +348,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, ISO8601Utils will be used. + * If the dateFormat is null, DateTimeFormatter will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -366,7 +373,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = ISO8601Utils.format(date, true); + value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); } out.value(value); } @@ -385,7 +392,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return ISO8601Utils.parse(date, new ParsePosition(0)); + return sdf.parse(date); } catch (ParseException e) { throw new JsonParseException(e); } diff --git a/samples/client/petstore/java/okhttp-gson/pom.xml b/samples/client/petstore/java/okhttp-gson/pom.xml index 5bd5c322feee..dbf329da8a70 100644 --- a/samples/client/petstore/java/okhttp-gson/pom.xml +++ b/samples/client/petstore/java/okhttp-gson/pom.xml @@ -305,6 +305,11 @@ jackson-databind-nullable ${jackson-databind-nullable-version} + + com.fasterxml.jackson.core + jackson-databind + ${jackson-databind-version} + javax.ws.rs jsr311-api @@ -345,6 +350,7 @@ 2.10.1 3.13.0 0.2.6 + 2.16.0 1.3.5 5.10.0 1.10.0 diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java index bcad4347e627..bb9e13578d36 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java @@ -13,11 +13,11 @@ package org.openapitools.client; +import com.fasterxml.jackson.databind.util.StdDateFormat; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; import com.google.gson.TypeAdapter; -import com.google.gson.internal.bind.util.ISO8601Utils; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import com.google.gson.JsonElement; @@ -31,14 +31,16 @@ import java.lang.reflect.Type; import java.text.DateFormat; import java.text.ParseException; -import java.text.ParsePosition; import java.time.LocalDate; import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.Locale; import java.util.Map; import java.util.HashMap; +import java.util.TimeZone; /* * A JSON utility class @@ -55,6 +57,11 @@ public class JSON { private static LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter(); private static ByteArrayAdapter byteArrayAdapter = new ByteArrayAdapter(); + private static final StdDateFormat sdf = new StdDateFormat() + .withTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault())) + .withColonInTimeZone(true); + private static final DateTimeFormatter dtf = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + @SuppressWarnings("unchecked") public static GsonBuilder createGson() { GsonFireBuilder fireBuilder = new GsonFireBuilder() @@ -545,7 +552,7 @@ public java.sql.Date read(JsonReader in) throws IOException { if (dateFormat != null) { return new java.sql.Date(dateFormat.parse(date).getTime()); } - return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); + return new java.sql.Date(sdf.parse(date).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -555,7 +562,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, ISO8601Utils will be used. + * If the dateFormat is null, DateTimeFormatter will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -580,7 +587,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = ISO8601Utils.format(date, true); + value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); } out.value(value); } @@ -599,7 +606,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return ISO8601Utils.parse(date, new ParsePosition(0)); + return sdf.parse(date); } catch (ParseException e) { throw new JsonParseException(e); } diff --git a/samples/client/petstore/java/rest-assured-jackson/pom.xml b/samples/client/petstore/java/rest-assured-jackson/pom.xml index 0a0c91d0e4d3..fd3d992caddc 100644 --- a/samples/client/petstore/java/rest-assured-jackson/pom.xml +++ b/samples/client/petstore/java/rest-assured-jackson/pom.xml @@ -227,18 +227,19 @@ rest-assured ${rest-assured.version} - com.fasterxml.jackson.core - jackson-core + jackson-databind + ${jackson-databind-version} + com.fasterxml.jackson.core - jackson-annotations + jackson-core com.fasterxml.jackson.core - jackson-databind + jackson-annotations org.openapitools @@ -280,8 +281,8 @@ 5.3.2 2.10.1 1.9.0 - 2.15.2 2.15.2 + 2.15.2 0.2.6 1.3.5 2.0.2 diff --git a/samples/client/petstore/java/rest-assured/pom.xml b/samples/client/petstore/java/rest-assured/pom.xml index 4ba82ad7c648..066e10e5e67d 100644 --- a/samples/client/petstore/java/rest-assured/pom.xml +++ b/samples/client/petstore/java/rest-assured/pom.xml @@ -226,6 +226,11 @@ gson-fire ${gson-fire-version} + + com.fasterxml.jackson.core + jackson-databind + ${jackson-databind-version} + com.squareup.okio okio @@ -257,6 +262,7 @@ 5.3.2 2.10.1 1.9.0 + 2.15.2 1.3.5 2.0.2 3.6.0 diff --git a/samples/client/petstore/java/rest-assured/src/main/java/org/openapitools/client/JSON.java b/samples/client/petstore/java/rest-assured/src/main/java/org/openapitools/client/JSON.java index edcc9eed5b95..5f2e9f70d674 100644 --- a/samples/client/petstore/java/rest-assured/src/main/java/org/openapitools/client/JSON.java +++ b/samples/client/petstore/java/rest-assured/src/main/java/org/openapitools/client/JSON.java @@ -13,11 +13,11 @@ package org.openapitools.client; +import com.fasterxml.jackson.databind.util.StdDateFormat; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; import com.google.gson.TypeAdapter; -import com.google.gson.internal.bind.util.ISO8601Utils; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import com.google.gson.JsonElement; @@ -35,11 +35,14 @@ import java.text.ParsePosition; import java.time.LocalDate; import java.time.OffsetDateTime; +import java.time.ZoneOffset; +import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.Locale; import java.util.Map; import java.util.HashMap; +import java.util.TimeZone; public class JSON { private Gson gson; @@ -50,6 +53,11 @@ public class JSON { private LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter(); private ByteArrayAdapter byteArrayAdapter = new ByteArrayAdapter(); + private static final StdDateFormat sdf = new StdDateFormat() + .withTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault())) + .withColonInTimeZone(true); + private static final DateTimeFormatter dtf = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + @SuppressWarnings("unchecked") public static GsonBuilder createGson() { GsonFireBuilder fireBuilder = new GsonFireBuilder() @@ -372,7 +380,7 @@ public java.sql.Date read(JsonReader in) throws IOException { if (dateFormat != null) { return new java.sql.Date(dateFormat.parse(date).getTime()); } - return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); + return new java.sql.Date(sdf.parse(date).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -382,7 +390,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, ISO8601Utils will be used. + * If the dateFormat is null, DateTimeFormatter will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -407,7 +415,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = ISO8601Utils.format(date, true); + value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); } out.value(value); } @@ -426,7 +434,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return ISO8601Utils.parse(date, new ParsePosition(0)); + return sdf.parse(date); } catch (ParseException e) { throw new JsonParseException(e); } diff --git a/samples/client/petstore/java/retrofit2-play26/pom.xml b/samples/client/petstore/java/retrofit2-play26/pom.xml index 3101a86f19a9..cad74ede3af2 100644 --- a/samples/client/petstore/java/retrofit2-play26/pom.xml +++ b/samples/client/petstore/java/retrofit2-play26/pom.xml @@ -204,6 +204,11 @@ swagger-annotations ${swagger-annotations-version} + + com.fasterxml.jackson.core + jackson-databind + ${jackson-databind-version} + com.google.code.findbugs @@ -257,11 +262,6 @@ jackson-annotations ${jackson-version} - - com.fasterxml.jackson.core - jackson-databind - ${jackson-databind-version} - org.openapitools jackson-databind-nullable @@ -303,8 +303,8 @@ ${java.version} 1.9.0 1.6.3 - 2.15.2 2.15.2 + 2.15.2 2.6.7 0.2.6 2.5.0 diff --git a/samples/client/petstore/java/retrofit2/pom.xml b/samples/client/petstore/java/retrofit2/pom.xml index d3247005cc28..3ad49871d3c2 100644 --- a/samples/client/petstore/java/retrofit2/pom.xml +++ b/samples/client/petstore/java/retrofit2/pom.xml @@ -204,6 +204,11 @@ swagger-annotations ${swagger-annotations-version} + + com.fasterxml.jackson.core + jackson-databind + ${jackson-databind-version} + com.google.code.findbugs @@ -262,6 +267,7 @@ ${java.version} 1.9.0 1.6.3 + 2.15.2 2.5.0 1.3.5 1.0.1 diff --git a/samples/client/petstore/java/retrofit2/src/main/java/org/openapitools/client/JSON.java b/samples/client/petstore/java/retrofit2/src/main/java/org/openapitools/client/JSON.java index 65ad4ef6f55d..bce9a553a7d9 100644 --- a/samples/client/petstore/java/retrofit2/src/main/java/org/openapitools/client/JSON.java +++ b/samples/client/petstore/java/retrofit2/src/main/java/org/openapitools/client/JSON.java @@ -13,11 +13,11 @@ package org.openapitools.client; +import com.fasterxml.jackson.databind.util.StdDateFormat; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; import com.google.gson.TypeAdapter; -import com.google.gson.internal.bind.util.ISO8601Utils; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import com.google.gson.JsonElement; @@ -34,11 +34,14 @@ import java.text.ParsePosition; import java.time.LocalDate; import java.time.OffsetDateTime; +import java.time.ZoneOffset; +import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.Locale; import java.util.Map; import java.util.HashMap; +import java.util.TimeZone; public class JSON { private Gson gson; @@ -47,6 +50,11 @@ public class JSON { private OffsetDateTimeTypeAdapter offsetDateTimeTypeAdapter = new OffsetDateTimeTypeAdapter(); private LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter(); + private static final StdDateFormat sdf = new StdDateFormat() + .withTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault())) + .withColonInTimeZone(true); + private static final DateTimeFormatter dtf = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + public static GsonBuilder createGson() { GsonFireBuilder fireBuilder = new GsonFireBuilder() .registerTypeSelector(Animal.class, new TypeSelector() { @@ -285,7 +293,7 @@ public java.sql.Date read(JsonReader in) throws IOException { if (dateFormat != null) { return new java.sql.Date(dateFormat.parse(date).getTime()); } - return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); + return new java.sql.Date(sdf.parse(date).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -295,7 +303,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, ISO8601Utils will be used. + * If the dateFormat is null, DateTimeFormatter will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -321,7 +329,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = ISO8601Utils.format(date, true); + value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); } out.value(value); } @@ -340,7 +348,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return ISO8601Utils.parse(date, new ParsePosition(0)); + return sdf.parse(date); } catch (ParseException e) { throw new JsonParseException(e); } diff --git a/samples/client/petstore/java/retrofit2rx2/pom.xml b/samples/client/petstore/java/retrofit2rx2/pom.xml index fcec0a8541f0..8bf7b759f421 100644 --- a/samples/client/petstore/java/retrofit2rx2/pom.xml +++ b/samples/client/petstore/java/retrofit2rx2/pom.xml @@ -204,6 +204,11 @@ swagger-annotations ${swagger-annotations-version} + + com.fasterxml.jackson.core + jackson-databind + ${jackson-databind-version} + com.google.code.findbugs @@ -272,6 +277,7 @@ ${java.version} 1.9.0 1.6.3 + 2.15.2 2.5.0 2.1.1 1.3.5 diff --git a/samples/client/petstore/java/retrofit2rx2/src/main/java/org/openapitools/client/JSON.java b/samples/client/petstore/java/retrofit2rx2/src/main/java/org/openapitools/client/JSON.java index 65ad4ef6f55d..bce9a553a7d9 100644 --- a/samples/client/petstore/java/retrofit2rx2/src/main/java/org/openapitools/client/JSON.java +++ b/samples/client/petstore/java/retrofit2rx2/src/main/java/org/openapitools/client/JSON.java @@ -13,11 +13,11 @@ package org.openapitools.client; +import com.fasterxml.jackson.databind.util.StdDateFormat; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; import com.google.gson.TypeAdapter; -import com.google.gson.internal.bind.util.ISO8601Utils; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import com.google.gson.JsonElement; @@ -34,11 +34,14 @@ import java.text.ParsePosition; import java.time.LocalDate; import java.time.OffsetDateTime; +import java.time.ZoneOffset; +import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.Locale; import java.util.Map; import java.util.HashMap; +import java.util.TimeZone; public class JSON { private Gson gson; @@ -47,6 +50,11 @@ public class JSON { private OffsetDateTimeTypeAdapter offsetDateTimeTypeAdapter = new OffsetDateTimeTypeAdapter(); private LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter(); + private static final StdDateFormat sdf = new StdDateFormat() + .withTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault())) + .withColonInTimeZone(true); + private static final DateTimeFormatter dtf = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + public static GsonBuilder createGson() { GsonFireBuilder fireBuilder = new GsonFireBuilder() .registerTypeSelector(Animal.class, new TypeSelector() { @@ -285,7 +293,7 @@ public java.sql.Date read(JsonReader in) throws IOException { if (dateFormat != null) { return new java.sql.Date(dateFormat.parse(date).getTime()); } - return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); + return new java.sql.Date(sdf.parse(date).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -295,7 +303,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, ISO8601Utils will be used. + * If the dateFormat is null, DateTimeFormatter will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -321,7 +329,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = ISO8601Utils.format(date, true); + value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); } out.value(value); } @@ -340,7 +348,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return ISO8601Utils.parse(date, new ParsePosition(0)); + return sdf.parse(date); } catch (ParseException e) { throw new JsonParseException(e); } diff --git a/samples/client/petstore/java/retrofit2rx3/pom.xml b/samples/client/petstore/java/retrofit2rx3/pom.xml index d1a000cf6796..0df159efe6d4 100644 --- a/samples/client/petstore/java/retrofit2rx3/pom.xml +++ b/samples/client/petstore/java/retrofit2rx3/pom.xml @@ -204,6 +204,11 @@ swagger-annotations ${swagger-annotations-version} + + com.fasterxml.jackson.core + jackson-databind + ${jackson-databind-version} + com.google.code.findbugs @@ -272,6 +277,7 @@ ${java.version} 1.9.0 1.6.3 + 2.15.2 2.5.0 3.0.4 1.3.5 diff --git a/samples/client/petstore/java/retrofit2rx3/src/main/java/org/openapitools/client/JSON.java b/samples/client/petstore/java/retrofit2rx3/src/main/java/org/openapitools/client/JSON.java index 65ad4ef6f55d..bce9a553a7d9 100644 --- a/samples/client/petstore/java/retrofit2rx3/src/main/java/org/openapitools/client/JSON.java +++ b/samples/client/petstore/java/retrofit2rx3/src/main/java/org/openapitools/client/JSON.java @@ -13,11 +13,11 @@ package org.openapitools.client; +import com.fasterxml.jackson.databind.util.StdDateFormat; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; import com.google.gson.TypeAdapter; -import com.google.gson.internal.bind.util.ISO8601Utils; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import com.google.gson.JsonElement; @@ -34,11 +34,14 @@ import java.text.ParsePosition; import java.time.LocalDate; import java.time.OffsetDateTime; +import java.time.ZoneOffset; +import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.Locale; import java.util.Map; import java.util.HashMap; +import java.util.TimeZone; public class JSON { private Gson gson; @@ -47,6 +50,11 @@ public class JSON { private OffsetDateTimeTypeAdapter offsetDateTimeTypeAdapter = new OffsetDateTimeTypeAdapter(); private LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter(); + private static final StdDateFormat sdf = new StdDateFormat() + .withTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault())) + .withColonInTimeZone(true); + private static final DateTimeFormatter dtf = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + public static GsonBuilder createGson() { GsonFireBuilder fireBuilder = new GsonFireBuilder() .registerTypeSelector(Animal.class, new TypeSelector() { @@ -285,7 +293,7 @@ public java.sql.Date read(JsonReader in) throws IOException { if (dateFormat != null) { return new java.sql.Date(dateFormat.parse(date).getTime()); } - return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); + return new java.sql.Date(sdf.parse(date).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -295,7 +303,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, ISO8601Utils will be used. + * If the dateFormat is null, DateTimeFormatter will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -321,7 +329,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = ISO8601Utils.format(date, true); + value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); } out.value(value); } @@ -340,7 +348,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return ISO8601Utils.parse(date, new ParsePosition(0)); + return sdf.parse(date); } catch (ParseException e) { throw new JsonParseException(e); }