replace deprecated ISO8601Utils with StdDateFormat (#17052)

This commit is contained in:
Marc Weiß 2024-01-11 11:24:52 +01:00 committed by GitHub
parent be19c35c45
commit 76560e34c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 320 additions and 137 deletions

View File

@ -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;
}
}
@Override
public Date parse(String source, ParsePosition pos) {
return sdf.parse(source, pos);
}
}

View File

@ -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<Date> {
@ -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);
}

View File

@ -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<Date> {
@ -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);
}

View File

@ -271,6 +271,11 @@
<version>${gson-fire-version}</version>
</dependency>
{{/gson}}
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind-version}</version>
</dependency>
{{#jackson}}
<!-- JSON processing: jackson -->
<dependency>
@ -281,10 +286,6 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
@ -351,9 +352,9 @@
{{#joda}}
<jodatime-version>2.10.5</jodatime-version>
{{/joda}}
<jackson-databind-version>2.15.2</jackson-databind-version>
{{#jackson}}
<jackson-version>2.15.2</jackson-version>
<jackson-databind-version>2.15.2</jackson-databind-version>
<jackson-databind-nullable-version>0.2.6</jackson-databind-nullable-version>
{{/jackson}}
{{#useJakartaEe}}

View File

@ -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<Date> {
@ -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);
}

View File

@ -211,6 +211,11 @@
<artifactId>swagger-annotations</artifactId>
<version>${swagger-annotations-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind-version}</version>
</dependency>
<!-- @Nullable annotation -->
<dependency>
<groupId>com.google.code.findbugs</groupId>
@ -296,11 +301,6 @@
<artifactId>jackson-annotations</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind-version}</version>
</dependency>
{{#openApiNullable}}
<dependency>
<groupId>org.openapitools</groupId>
@ -362,9 +362,9 @@
<maven.compiler.target>${java.version}</maven.compiler.target>
<gson-fire-version>1.9.0</gson-fire-version>
<swagger-annotations-version>1.6.3</swagger-annotations-version>
<jackson-databind-version>2.15.2</jackson-databind-version>
{{#usePlayWS}}
<jackson-version>2.15.2</jackson-version>
<jackson-databind-version>2.15.2</jackson-databind-version>
<play-version>2.6.7</play-version>
{{#openApiNullable}}
<jackson-databind-nullable-version>0.2.6</jackson-databind-nullable-version>

View File

@ -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.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
@ -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 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);
}
@ -344,7 +351,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<Date> {
@ -369,7 +376,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);
}
@ -388,7 +395,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);
}

View File

@ -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.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
@ -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 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);
}
@ -336,7 +343,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<Date> {
@ -361,7 +368,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);
}
@ -380,7 +387,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);
}

View File

@ -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.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
@ -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 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);
}
@ -337,7 +344,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<Date> {
@ -362,7 +369,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);
}
@ -381,7 +388,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);
}

View File

@ -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.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
@ -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()
@ -365,7 +372,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);
}
@ -375,7 +382,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<Date> {
@ -400,7 +407,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);
}
@ -419,7 +426,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);
}

View File

@ -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.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
@ -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 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);
}
@ -341,7 +348,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<Date> {
@ -366,7 +373,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);
}
@ -385,7 +392,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);
}

View File

@ -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.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
@ -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 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);
}
@ -416,7 +423,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<Date> {
@ -441,7 +448,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);
}
@ -460,7 +467,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);
}

View File

@ -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.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
@ -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 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);
}
@ -341,7 +348,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<Date> {
@ -366,7 +373,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);
}
@ -385,7 +392,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);
}

View File

@ -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.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
@ -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 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);
}
@ -343,7 +350,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<Date> {
@ -368,7 +375,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);
}
@ -387,7 +394,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);
}

View File

@ -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.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
@ -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 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);
}
@ -416,7 +423,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<Date> {
@ -441,7 +448,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);
}
@ -460,7 +467,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);
}

View File

@ -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.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
@ -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 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);
}
@ -341,7 +348,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<Date> {
@ -366,7 +373,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);
}
@ -385,7 +392,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);
}

View File

@ -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.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
@ -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 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);
}
@ -341,7 +348,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<Date> {
@ -366,7 +373,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);
}
@ -385,7 +392,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);
}

View File

@ -305,6 +305,11 @@
<artifactId>jackson-databind-nullable</artifactId>
<version>${jackson-databind-nullable-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind-version}</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
@ -345,6 +350,7 @@
<gson-version>2.10.1</gson-version>
<commons-lang3-version>3.13.0</commons-lang3-version>
<jackson-databind-nullable-version>0.2.6</jackson-databind-nullable-version>
<jackson-databind-version>2.16.0</jackson-databind-version>
<jakarta-annotation-version>1.3.5</jakarta-annotation-version>
<junit-version>5.10.0</junit-version>
<junit-platform-runner.version>1.10.0</junit-platform-runner.version>

View File

@ -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.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
@ -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 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);
}
@ -555,7 +562,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<Date> {
@ -580,7 +587,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);
}
@ -599,7 +606,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);
}

View File

@ -227,6 +227,11 @@
<artifactId>rest-assured</artifactId>
<version>${rest-assured.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind-version}</version>
</dependency>
<!-- JSON processing: jackson -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
@ -236,10 +241,6 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
@ -280,8 +281,8 @@
<rest-assured.version>5.3.2</rest-assured.version>
<gson-version>2.10.1</gson-version>
<gson-fire-version>1.9.0</gson-fire-version>
<jackson-version>2.15.2</jackson-version>
<jackson-databind-version>2.15.2</jackson-databind-version>
<jackson-version>2.15.2</jackson-version>
<jackson-databind-nullable-version>0.2.6</jackson-databind-nullable-version>
<jakarta-annotation-version>1.3.5</jakarta-annotation-version>
<beanvalidation-version>2.0.2</beanvalidation-version>

View File

@ -226,6 +226,11 @@
<artifactId>gson-fire</artifactId>
<version>${gson-fire-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind-version}</version>
</dependency>
<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
@ -257,6 +262,7 @@
<rest-assured.version>5.3.2</rest-assured.version>
<gson-version>2.10.1</gson-version>
<gson-fire-version>1.9.0</gson-fire-version>
<jackson-databind-version>2.15.2</jackson-databind-version>
<jakarta-annotation-version>1.3.5</jakarta-annotation-version>
<beanvalidation-version>2.0.2</beanvalidation-version>
<okio-version>3.6.0</okio-version>

View File

@ -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.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;
@ -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 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);
}
@ -382,7 +390,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<Date> {
@ -407,7 +415,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);
}
@ -426,7 +434,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);
}

View File

@ -204,6 +204,11 @@
<artifactId>swagger-annotations</artifactId>
<version>${swagger-annotations-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind-version}</version>
</dependency>
<!-- @Nullable annotation -->
<dependency>
<groupId>com.google.code.findbugs</groupId>
@ -257,11 +262,6 @@
<artifactId>jackson-annotations</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind-version}</version>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
@ -303,8 +303,8 @@
<maven.compiler.target>${java.version}</maven.compiler.target>
<gson-fire-version>1.9.0</gson-fire-version>
<swagger-annotations-version>1.6.3</swagger-annotations-version>
<jackson-version>2.15.2</jackson-version>
<jackson-databind-version>2.15.2</jackson-databind-version>
<jackson-version>2.15.2</jackson-version>
<play-version>2.6.7</play-version>
<jackson-databind-nullable-version>0.2.6</jackson-databind-nullable-version>
<retrofit-version>2.5.0</retrofit-version>

View File

@ -204,6 +204,11 @@
<artifactId>swagger-annotations</artifactId>
<version>${swagger-annotations-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind-version}</version>
</dependency>
<!-- @Nullable annotation -->
<dependency>
<groupId>com.google.code.findbugs</groupId>
@ -262,6 +267,7 @@
<maven.compiler.target>${java.version}</maven.compiler.target>
<gson-fire-version>1.9.0</gson-fire-version>
<swagger-annotations-version>1.6.3</swagger-annotations-version>
<jackson-databind-version>2.15.2</jackson-databind-version>
<retrofit-version>2.5.0</retrofit-version>
<jakarta-annotation-version>1.3.5</jakarta-annotation-version>
<oltu-version>1.0.1</oltu-version>

View File

@ -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.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;
@ -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 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);
}
@ -295,7 +303,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<Date> {
@ -321,7 +329,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);
}
@ -340,7 +348,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);
}

View File

@ -204,6 +204,11 @@
<artifactId>swagger-annotations</artifactId>
<version>${swagger-annotations-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind-version}</version>
</dependency>
<!-- @Nullable annotation -->
<dependency>
<groupId>com.google.code.findbugs</groupId>
@ -272,6 +277,7 @@
<maven.compiler.target>${java.version}</maven.compiler.target>
<gson-fire-version>1.9.0</gson-fire-version>
<swagger-annotations-version>1.6.3</swagger-annotations-version>
<jackson-databind-version>2.15.2</jackson-databind-version>
<retrofit-version>2.5.0</retrofit-version>
<rxjava-version>2.1.1</rxjava-version>
<jakarta-annotation-version>1.3.5</jakarta-annotation-version>

View File

@ -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.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;
@ -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 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);
}
@ -295,7 +303,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<Date> {
@ -321,7 +329,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);
}
@ -340,7 +348,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);
}

View File

@ -204,6 +204,11 @@
<artifactId>swagger-annotations</artifactId>
<version>${swagger-annotations-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind-version}</version>
</dependency>
<!-- @Nullable annotation -->
<dependency>
<groupId>com.google.code.findbugs</groupId>
@ -272,6 +277,7 @@
<maven.compiler.target>${java.version}</maven.compiler.target>
<gson-fire-version>1.9.0</gson-fire-version>
<swagger-annotations-version>1.6.3</swagger-annotations-version>
<jackson-databind-version>2.15.2</jackson-databind-version>
<retrofit-version>2.5.0</retrofit-version>
<rxjava-version>3.0.4</rxjava-version>
<jakarta-annotation-version>1.3.5</jakarta-annotation-version>

View File

@ -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.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;
@ -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 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);
}
@ -295,7 +303,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<Date> {
@ -321,7 +329,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);
}
@ -340,7 +348,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);
}