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 9a089de40c361..fa2752bd6f8dc 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,35 +17,23 @@ package org.openapitools.codegen.online; -import com.fasterxml.jackson.databind.util.StdDateFormat; +import com.fasterxml.jackson.databind.util.ISO8601DateFormat; +import com.fasterxml.jackson.databind.util.ISO8601Utils; -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 DateFormat { + +public class RFC3339DateFormat extends ISO8601DateFormat { 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 = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); + String value = ISO8601Utils.format(date, true); toAppendTo.append(value); return toAppendTo; } - @Override - public Date parse(String source, ParsePosition pos) { - return sdf.parse(source, pos); - } - -} +} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/Java/JSON.mustache b/modules/openapi-generator/src/main/resources/Java/JSON.mustache index 0b4651d792823..1d0a8138787bb 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,14 +33,11 @@ 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; @@ -57,11 +54,6 @@ 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() @@ -469,7 +461,7 @@ public class JSON { if (dateFormat != null) { return new java.sql.Date(dateFormat.parse(date).getTime()); } - return new java.sql.Date(sdf.parse(date).getTime()); + return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -479,7 +471,7 @@ public class JSON { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, DateTimeFormatter will be used. + * If the dateFormat is null, ISO8601Utils will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -504,7 +496,7 @@ public class JSON { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); + value = ISO8601Utils.format(date, true); } out.value(value); } @@ -523,7 +515,7 @@ public class JSON { if (dateFormat != null) { return dateFormat.parse(date); } - return sdf.parse(date); + return ISO8601Utils.parse(date, new ParsePosition(0)); } 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 c6075a086949a..6cf7ec7898c4c 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,16 +27,14 @@ 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 @@ -59,11 +57,6 @@ 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() @@ -466,7 +459,7 @@ public class JSON { if (dateFormat != null) { return new java.sql.Date(dateFormat.parse(date).getTime()); } - return new java.sql.Date(sdf.parse(date).getTime()); + return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -476,7 +469,7 @@ public class JSON { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, DateTimeFormatter will be used. + * If the dateFormat is null, ISO8601Utils will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -501,7 +494,7 @@ public class JSON { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); + value = ISO8601Utils.format(date, true); } out.value(value); } @@ -520,7 +513,7 @@ public class JSON { if (dateFormat != null) { return dateFormat.parse(date); } - return sdf.parse(date); + return ISO8601Utils.parse(date, new ParsePosition(0)); } 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 a892488a245ad..1c8e41ee0242b 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,11 +271,6 @@ ${gson-fire-version} {{/gson}} - - com.fasterxml.jackson.core - jackson-databind - ${jackson-databind-version} - {{#jackson}} @@ -286,6 +281,10 @@ com.fasterxml.jackson.core jackson-annotations + + com.fasterxml.jackson.core + jackson-databind + org.openapitools jackson-databind-nullable @@ -352,9 +351,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 2d791d4ff5880..2ff8b1cb739c7 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,14 +32,11 @@ 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,11 +51,6 @@ 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() { @@ -370,7 +362,7 @@ public class JSON { if (dateFormat != null) { return new java.sql.Date(dateFormat.parse(date).getTime()); } - return new java.sql.Date(sdf.parse(date).getTime()); + return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -380,7 +372,7 @@ public class JSON { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, DateTimeFormatter will be used. + * If the dateFormat is null, ISO8601Utils will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -406,7 +398,7 @@ public class JSON { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); + value = ISO8601Utils.format(date, true); } out.value(value); } @@ -425,7 +417,7 @@ public class JSON { if (dateFormat != null) { return dateFormat.parse(date); } - return sdf.parse(date); + return ISO8601Utils.parse(date, new ParsePosition(0)); } 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 20b5c80c7c244..a610e2bd31630 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 @@ -305,6 +305,11 @@ jackson-annotations ${jackson-version} + + com.fasterxml.jackson.core + jackson-databind + ${jackson-databind-version} + {{#openApiNullable}} org.openapitools @@ -344,6 +349,11 @@ play-ahc-ws_2.12 ${play-version} + + jakarta.validation + jakarta.validation-api + ${beanvalidation-version} + {{/usePlayWS}} {{#parcelableModel}} @@ -377,12 +387,12 @@ 1.9.0 {{/gson}} 1.6.3 - 2.15.2 {{#jackson}} + 2.15.2 2.15.2 - {{#openApiNullable}} + {{#openApiNullable}} 0.2.6 - {{/openApiNullable}} + {{/openApiNullable}} 2.1.1 {{/jackson}} {{#usePlayWS}} 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 1520a2c935731..247f3cf0c99c6 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,16 +31,14 @@ 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,11 +55,6 @@ 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() @@ -342,7 +335,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(sdf.parse(date).getTime()); + return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -352,7 +345,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, DateTimeFormatter will be used. + * If the dateFormat is null, ISO8601Utils will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -377,7 +370,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); + value = ISO8601Utils.format(date, true); } out.value(value); } @@ -396,7 +389,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return sdf.parse(date); + return ISO8601Utils.parse(date, new ParsePosition(0)); } 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 f4e972e414e08..c6b151d0ccc0e 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,16 +31,14 @@ 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,11 +55,6 @@ 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 +326,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(sdf.parse(date).getTime()); + return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -343,7 +336,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, DateTimeFormatter will be used. + * If the dateFormat is null, ISO8601Utils will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -368,7 +361,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); + value = ISO8601Utils.format(date, true); } out.value(value); } @@ -387,7 +380,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return sdf.parse(date); + return ISO8601Utils.parse(date, new ParsePosition(0)); } 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 2aac67fb5b2b1..999628dc1f76f 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,16 +31,14 @@ 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,11 +55,6 @@ 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 +327,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(sdf.parse(date).getTime()); + return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -344,7 +337,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, DateTimeFormatter will be used. + * If the dateFormat is null, ISO8601Utils will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -369,7 +362,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); + value = ISO8601Utils.format(date, true); } out.value(value); } @@ -388,7 +381,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return sdf.parse(date); + return ISO8601Utils.parse(date, new ParsePosition(0)); } 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 f5823fd752244..6fe26034d7ed1 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,16 +31,14 @@ 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,11 +55,6 @@ 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() @@ -378,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(sdf.parse(date).getTime()); + return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -388,7 +381,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, DateTimeFormatter will be used. + * If the dateFormat is null, ISO8601Utils will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -413,7 +406,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); + value = ISO8601Utils.format(date, true); } out.value(value); } @@ -432,7 +425,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return sdf.parse(date); + return ISO8601Utils.parse(date, new ParsePosition(0)); } 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 ad2d26cbfbb76..f993e935c7aa4 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,16 +31,14 @@ 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,11 +55,6 @@ 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() @@ -338,7 +331,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(sdf.parse(date).getTime()); + return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -348,7 +341,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, DateTimeFormatter will be used. + * If the dateFormat is null, ISO8601Utils will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -373,7 +366,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); + value = ISO8601Utils.format(date, true); } out.value(value); } @@ -392,7 +385,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return sdf.parse(date); + return ISO8601Utils.parse(date, new ParsePosition(0)); } 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 349f4ff81132a..6d80edba2a7bf 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,16 +31,14 @@ 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,11 +55,6 @@ 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() @@ -413,7 +406,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(sdf.parse(date).getTime()); + return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -423,7 +416,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, DateTimeFormatter will be used. + * If the dateFormat is null, ISO8601Utils will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -448,7 +441,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); + value = ISO8601Utils.format(date, true); } out.value(value); } @@ -467,7 +460,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return sdf.parse(date); + return ISO8601Utils.parse(date, new ParsePosition(0)); } 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 ad2d26cbfbb76..f993e935c7aa4 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,16 +31,14 @@ 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,11 +55,6 @@ 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() @@ -338,7 +331,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(sdf.parse(date).getTime()); + return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -348,7 +341,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, DateTimeFormatter will be used. + * If the dateFormat is null, ISO8601Utils will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -373,7 +366,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); + value = ISO8601Utils.format(date, true); } out.value(value); } @@ -392,7 +385,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return sdf.parse(date); + return ISO8601Utils.parse(date, new ParsePosition(0)); } 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 75faa7a82b3f8..cc08e8c32f432 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,16 +31,14 @@ 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,11 +55,6 @@ 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() @@ -340,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(sdf.parse(date).getTime()); + return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -350,7 +343,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, DateTimeFormatter will be used. + * If the dateFormat is null, ISO8601Utils will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -375,7 +368,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); + value = ISO8601Utils.format(date, true); } out.value(value); } @@ -394,7 +387,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return sdf.parse(date); + return ISO8601Utils.parse(date, new ParsePosition(0)); } 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 349f4ff81132a..6d80edba2a7bf 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,16 +31,14 @@ 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,11 +55,6 @@ 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() @@ -413,7 +406,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(sdf.parse(date).getTime()); + return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -423,7 +416,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, DateTimeFormatter will be used. + * If the dateFormat is null, ISO8601Utils will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -448,7 +441,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); + value = ISO8601Utils.format(date, true); } out.value(value); } @@ -467,7 +460,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return sdf.parse(date); + return ISO8601Utils.parse(date, new ParsePosition(0)); } 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 ad2d26cbfbb76..f993e935c7aa4 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,16 +31,14 @@ 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,11 +55,6 @@ 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() @@ -338,7 +331,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(sdf.parse(date).getTime()); + return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -348,7 +341,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, DateTimeFormatter will be used. + * If the dateFormat is null, ISO8601Utils will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -373,7 +366,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); + value = ISO8601Utils.format(date, true); } out.value(value); } @@ -392,7 +385,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return sdf.parse(date); + return ISO8601Utils.parse(date, new ParsePosition(0)); } 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 ad2d26cbfbb76..f993e935c7aa4 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,16 +31,14 @@ 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,11 +55,6 @@ 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() @@ -338,7 +331,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(sdf.parse(date).getTime()); + return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -348,7 +341,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, DateTimeFormatter will be used. + * If the dateFormat is null, ISO8601Utils will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -373,7 +366,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); + value = ISO8601Utils.format(date, true); } out.value(value); } @@ -392,7 +385,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return sdf.parse(date); + return ISO8601Utils.parse(date, new ParsePosition(0)); } 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 dbf329da8a707..5bd5c322feeea 100644 --- a/samples/client/petstore/java/okhttp-gson/pom.xml +++ b/samples/client/petstore/java/okhttp-gson/pom.xml @@ -305,11 +305,6 @@ jackson-databind-nullable ${jackson-databind-nullable-version} - - com.fasterxml.jackson.core - jackson-databind - ${jackson-databind-version} - javax.ws.rs jsr311-api @@ -350,7 +345,6 @@ 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 db57f2dbba89b..d13cb5a17e5ae 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,16 +31,14 @@ 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,11 +55,6 @@ 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() @@ -562,7 +555,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(sdf.parse(date).getTime()); + return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -572,7 +565,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, DateTimeFormatter will be used. + * If the dateFormat is null, ISO8601Utils will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -597,7 +590,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); + value = ISO8601Utils.format(date, true); } out.value(value); } @@ -616,7 +609,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return sdf.parse(date); + return ISO8601Utils.parse(date, new ParsePosition(0)); } 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 499b537d6e625..30f05119867b5 100644 --- a/samples/client/petstore/java/rest-assured-jackson/pom.xml +++ b/samples/client/petstore/java/rest-assured-jackson/pom.xml @@ -227,11 +227,6 @@ rest-assured ${rest-assured.version} - - com.fasterxml.jackson.core - jackson-databind - ${jackson-databind-version} - com.fasterxml.jackson.core @@ -241,6 +236,10 @@ com.fasterxml.jackson.core jackson-annotations + + com.fasterxml.jackson.core + jackson-databind + org.openapitools jackson-databind-nullable @@ -281,8 +280,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 3.0.2 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 5f2e9f70d6748..edcc9eed5b955 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,14 +35,11 @@ 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; @@ -53,11 +50,6 @@ 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() @@ -380,7 +372,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(sdf.parse(date).getTime()); + return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -390,7 +382,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, DateTimeFormatter will be used. + * If the dateFormat is null, ISO8601Utils will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -415,7 +407,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); + value = ISO8601Utils.format(date, true); } out.value(value); } @@ -434,7 +426,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return sdf.parse(date); + return ISO8601Utils.parse(date, new ParsePosition(0)); } 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 25ad911845aad..fe70f28501bd0 100644 --- a/samples/client/petstore/java/retrofit2-play26/pom.xml +++ b/samples/client/petstore/java/retrofit2-play26/pom.xml @@ -204,11 +204,6 @@ swagger-annotations ${swagger-annotations-version} - - com.fasterxml.jackson.core - jackson-databind - ${jackson-databind-version} - com.google.code.findbugs @@ -252,6 +247,11 @@ jackson-annotations ${jackson-version} + + com.fasterxml.jackson.core + jackson-databind + ${jackson-databind-version} + org.openapitools jackson-databind-nullable @@ -297,8 +297,8 @@ ${java.version} ${java.version} 1.6.3 - 2.15.2 2.15.2 + 2.15.2 0.2.6 2.1.1 2.6.7 diff --git a/samples/client/petstore/java/retrofit2/pom.xml b/samples/client/petstore/java/retrofit2/pom.xml index 619349f68783c..27a703dff5653 100644 --- a/samples/client/petstore/java/retrofit2/pom.xml +++ b/samples/client/petstore/java/retrofit2/pom.xml @@ -204,11 +204,6 @@ swagger-annotations ${swagger-annotations-version} - - com.fasterxml.jackson.core - jackson-databind - ${jackson-databind-version} - com.google.code.findbugs @@ -267,7 +262,6 @@ ${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 bce9a553a7d9d..65ad4ef6f55d1 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,14 +34,11 @@ 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,11 +47,6 @@ 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() { @@ -293,7 +285,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(sdf.parse(date).getTime()); + return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -303,7 +295,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, DateTimeFormatter will be used. + * If the dateFormat is null, ISO8601Utils will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -329,7 +321,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); + value = ISO8601Utils.format(date, true); } out.value(value); } @@ -348,7 +340,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return sdf.parse(date); + return ISO8601Utils.parse(date, new ParsePosition(0)); } 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 62305514590e5..283c5647bd8b2 100644 --- a/samples/client/petstore/java/retrofit2rx2/pom.xml +++ b/samples/client/petstore/java/retrofit2rx2/pom.xml @@ -204,11 +204,6 @@ swagger-annotations ${swagger-annotations-version} - - com.fasterxml.jackson.core - jackson-databind - ${jackson-databind-version} - com.google.code.findbugs @@ -277,7 +272,6 @@ ${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 bce9a553a7d9d..65ad4ef6f55d1 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,14 +34,11 @@ 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,11 +47,6 @@ 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() { @@ -293,7 +285,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(sdf.parse(date).getTime()); + return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -303,7 +295,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, DateTimeFormatter will be used. + * If the dateFormat is null, ISO8601Utils will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -329,7 +321,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); + value = ISO8601Utils.format(date, true); } out.value(value); } @@ -348,7 +340,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return sdf.parse(date); + return ISO8601Utils.parse(date, new ParsePosition(0)); } 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 4abc9a52d93da..5546912ccb141 100644 --- a/samples/client/petstore/java/retrofit2rx3/pom.xml +++ b/samples/client/petstore/java/retrofit2rx3/pom.xml @@ -204,11 +204,6 @@ swagger-annotations ${swagger-annotations-version} - - com.fasterxml.jackson.core - jackson-databind - ${jackson-databind-version} - com.google.code.findbugs @@ -277,7 +272,6 @@ ${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 bce9a553a7d9d..65ad4ef6f55d1 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,14 +34,11 @@ 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,11 +47,6 @@ 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() { @@ -293,7 +285,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(sdf.parse(date).getTime()); + return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime()); } catch (ParseException e) { throw new JsonParseException(e); } @@ -303,7 +295,7 @@ public java.sql.Date read(JsonReader in) throws IOException { /** * Gson TypeAdapter for java.util.Date type - * If the dateFormat is null, DateTimeFormatter will be used. + * If the dateFormat is null, ISO8601Utils will be used. */ public static class DateTypeAdapter extends TypeAdapter { @@ -329,7 +321,7 @@ public void write(JsonWriter out, Date date) throws IOException { if (dateFormat != null) { value = dateFormat.format(date); } else { - value = date.toInstant().atOffset(ZoneOffset.UTC).format(dtf); + value = ISO8601Utils.format(date, true); } out.value(value); } @@ -348,7 +340,7 @@ public Date read(JsonReader in) throws IOException { if (dateFormat != null) { return dateFormat.parse(date); } - return sdf.parse(date); + return ISO8601Utils.parse(date, new ParsePosition(0)); } catch (ParseException e) { throw new JsonParseException(e); }