forked from loafle/openapi-generator-original
[JAVA: okhttp-gson, rest-assured, retrofit2] Don't generate Jackson import when serialization library is GSON (#18811)
* Partially revert "replace deprecated ISO8601Utils with StdDateFormat (#17052)"
This partially reverts commit 76560e34c9, namely anything
related to generators and samples using GSON instead of Jackson.
Changes to Jackson-only generation and generator-online regarding RFC3339DateFormat
are not being reverted.
* Test for default serialization library fallback
* Convert repetitive tests to parameterized test
* Add regression test for #18515
* [FEIGN] Only include <jackson-databind-version> property in pom.xml when required
* [RETROFIT2] Only include jackson-databind in gradle file when actually required
* [FEIGN] Don't include jackson dep's in sbt file when GSON is selected
* [FEIGN] Don't include jackson dep's in gradle file when GSON is selected
* DRY refactor JavaClientCodegen test code, increase readability
- use fluent assertions
- use helper method newTempFolder()
- use Java 9 static factory methods for maps
- don't declare variables that are only used once
- group declarations and usages
- use non-blocking java.nio.file API wherever possible
* Regenerate samples
This commit is contained in:
@@ -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.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,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 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);
|
||||
}
|
||||
@@ -352,7 +345,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<Date> {
|
||||
|
||||
@@ -377,7 +370,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);
|
||||
}
|
||||
@@ -396,7 +389,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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user