mirror of
https://github.com/jlengrand/openapi-generator.git
synced 2026-03-10 08:31:23 +00:00
Add java8 option 2.3.0 (#5955)
* Closes #5863 The "dateLibrary" option for java, sadly, sets a mustache value "java8". This change updates this so that "java" in the mustache libraries means what it should mean - use all java8 classes. In this case, there's no need for the third party Base64 library as java8's JDK has this built in. In my view, the "dateLibrary" should be deprecated but that should be a separate PR. * Closes #5954 built and ran tests/samples
This commit is contained in:
committed by
wing328
parent
fd44d01d9c
commit
40369bb819
@@ -45,9 +45,11 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
public static final String FULL_JAVA_UTIL = "fullJavaUtil";
|
||||
public static final String DEFAULT_LIBRARY = "<default>";
|
||||
public static final String DATE_LIBRARY = "dateLibrary";
|
||||
public static final String JAVA8_MODE = "java8";
|
||||
public static final String SUPPORT_JAVA6 = "supportJava6";
|
||||
|
||||
protected String dateLibrary = "threetenbp";
|
||||
protected boolean java8Mode = false;
|
||||
protected String invokerPackage = "io.swagger";
|
||||
protected String groupId = "io.swagger";
|
||||
protected String artifactId = "swagger-java";
|
||||
@@ -149,15 +151,21 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
|
||||
CliOption dateLibrary = new CliOption(DATE_LIBRARY, "Option. Date library to use");
|
||||
Map<String, String> dateOptions = new HashMap<String, String>();
|
||||
dateOptions.put("java8", "Java 8 native JSR310 (preferred for jdk 1.8+)");
|
||||
dateOptions.put("java8", "Java 8 native JSR310 (preferred for jdk 1.8+) - note: this also sets \"" + JAVA8_MODE + "\" to true");
|
||||
dateOptions.put("threetenbp", "Backport of JSR310 (preferred for jdk < 1.8)");
|
||||
dateOptions.put("java8-localdatetime", "Java 8 using LocalDateTime (for legacy app only)");
|
||||
dateOptions.put("joda", "Joda (for legacy app only)");
|
||||
dateOptions.put("legacy", "Legacy java.util.Date (if you really have a good reason not to use threetenbp");
|
||||
dateLibrary.setEnum(dateOptions);
|
||||
|
||||
cliOptions.add(dateLibrary);
|
||||
|
||||
CliOption java8Mode = new CliOption(JAVA8_MODE, "Option. Use Java8 classes instead of third party equivalents");
|
||||
Map<String, String> java8ModeOptions = new HashMap<String, String>();
|
||||
java8ModeOptions.put("true", "Use Java 8 classes such as Base64");
|
||||
java8ModeOptions.put("false", "Various third party libraries as needed");
|
||||
java8Mode.setEnum(java8ModeOptions);
|
||||
cliOptions.add(java8Mode);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -360,6 +368,13 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
// used later in recursive import in postProcessingModels
|
||||
importMapping.put("com.fasterxml.jackson.annotation.JsonProperty", "com.fasterxml.jackson.annotation.JsonCreator");
|
||||
|
||||
if(additionalProperties.containsKey(JAVA8_MODE)) {
|
||||
setJava8Mode(Boolean.parseBoolean(additionalProperties.get(JAVA8_MODE).toString()));
|
||||
if ( java8Mode ) {
|
||||
additionalProperties.put("java8", "true");
|
||||
}
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(DATE_LIBRARY)) {
|
||||
setDateLibrary(additionalProperties.get("dateLibrary").toString());
|
||||
}
|
||||
@@ -1134,6 +1149,10 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
this.dateLibrary = library;
|
||||
}
|
||||
|
||||
public void setJava8Mode(boolean enabled) {
|
||||
this.java8Mode = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeQuotationMark(String input) {
|
||||
// remove " to avoid code injection
|
||||
|
||||
@@ -4,12 +4,20 @@ package {{invokerPackage}}.auth;
|
||||
|
||||
import {{invokerPackage}}.Pair;
|
||||
|
||||
{{^java8}}
|
||||
import com.migcomponents.migbase64.Base64;
|
||||
{{/java8}}
|
||||
{{#java8}}
|
||||
import java.util.Base64;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
{{/java8}}
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
{{^java8}}
|
||||
import java.io.UnsupportedEncodingException;
|
||||
{{/java8}}
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
public class HttpBasicAuth implements Authentication {
|
||||
@@ -38,10 +46,15 @@ public class HttpBasicAuth implements Authentication {
|
||||
return;
|
||||
}
|
||||
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
|
||||
{{^java8}}
|
||||
try {
|
||||
headerParams.put("Authorization", "Basic " + Base64.encodeToString(str.getBytes("UTF-8"), false));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
{{/java8}}
|
||||
{{#java8}}
|
||||
headerParams.put("Authorization", "Basic " + Base64.getEncoder().encodeToString(str.getBytes(StandardCharsets.UTF_8)));
|
||||
{{/java8}}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,6 +130,8 @@ dependencies {
|
||||
{{#threetenbp}}
|
||||
compile "com.github.joschi.jackson:jackson-datatype-threetenbp:$jackson_version",
|
||||
{{/threetenbp}}
|
||||
{{^java8}}
|
||||
compile "com.brsanthu:migbase64:2.2"
|
||||
{{/java8}}
|
||||
testCompile "junit:junit:$junit_version"
|
||||
}
|
||||
|
||||
@@ -136,6 +136,8 @@ dependencies {
|
||||
{{#threetenbp}}
|
||||
compile "com.github.joschi.jackson:jackson-datatype-threetenbp:$jackson_version",
|
||||
{{/threetenbp}}
|
||||
{{^java8}}
|
||||
compile "com.brsanthu:migbase64:2.2"
|
||||
{{/java8}}
|
||||
testCompile "junit:junit:$junit_version"
|
||||
}
|
||||
|
||||
@@ -25,7 +25,9 @@ lazy val root = (project in file(".")).
|
||||
{{#threetenbp}}
|
||||
"com.github.joschi.jackson" % "jackson-datatype-threetenbp" % "2.6.4" % "compile",
|
||||
{{/threetenbp}}
|
||||
{{^java8}}
|
||||
"com.brsanthu" % "migbase64" % "2.2",
|
||||
{{/java8}}
|
||||
{{#supportJava6}}
|
||||
"org.apache.commons" % "commons-lang3" % "3.6",
|
||||
"commons-io" % "commons-io" % "2.5",
|
||||
|
||||
@@ -244,12 +244,14 @@
|
||||
</dependency>
|
||||
{{/threetenbp}}
|
||||
|
||||
{{^java8}}
|
||||
<!-- Base64 encoding that works in both JVM and Android -->
|
||||
<dependency>
|
||||
<groupId>com.brsanthu</groupId>
|
||||
<artifactId>migbase64</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
{{/java8}}
|
||||
{{#supportJava6}}
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
|
||||
@@ -132,11 +132,11 @@ dependencies {
|
||||
{{^java8}}
|
||||
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:$jackson_version"
|
||||
compile "joda-time:joda-time:$jodatime_version"
|
||||
compile "com.brsanthu:migbase64:2.2"
|
||||
{{/java8}}
|
||||
{{#supportJava6}}
|
||||
compile "commons-io:commons-io:$commons_io_version"
|
||||
compile "org.apache.commons:commons-lang3:$commons_lang3_version"
|
||||
{{/supportJava6}}
|
||||
compile "com.brsanthu:migbase64:2.2"
|
||||
testCompile "junit:junit:$junit_version"
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ lazy val root = (project in file(".")).
|
||||
{{^java8}}
|
||||
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % "2.7.5",
|
||||
"joda-time" % "joda-time" % "2.9.4",
|
||||
{{/java8}}
|
||||
"com.brsanthu" % "migbase64" % "2.2",
|
||||
{{/java8}}
|
||||
{{#supportJava6}}
|
||||
"org.apache.commons" % "commons-lang3" % "3.5",
|
||||
"commons-io" % "commons-io" % "2.5",
|
||||
|
||||
@@ -168,7 +168,6 @@
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>${jodatime-version}</version>
|
||||
</dependency>
|
||||
{{/java8}}
|
||||
|
||||
<!-- Base64 encoding that works in both JVM and Android -->
|
||||
<dependency>
|
||||
@@ -176,6 +175,8 @@
|
||||
<artifactId>migbase64</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
{{/java8}}
|
||||
|
||||
{{#supportJava6}}
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
|
||||
@@ -245,12 +245,14 @@
|
||||
</dependency>
|
||||
{{/threetenbp}}
|
||||
|
||||
{{^java8}}
|
||||
<!-- Base64 encoding that works in both JVM and Android -->
|
||||
<dependency>
|
||||
<groupId>com.brsanthu</groupId>
|
||||
<artifactId>migbase64</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
{{/java8}}
|
||||
|
||||
{{#supportJava6}}
|
||||
<dependency>
|
||||
|
||||
@@ -29,6 +29,7 @@ public class JavaOptionsProvider implements OptionsProvider {
|
||||
public static final String LOCAL_PREFIX_VALUE = "tst";
|
||||
public static final String SERIALIZABLE_MODEL_VALUE = "false";
|
||||
public static final String FULL_JAVA_UTIL_VALUE = "true";
|
||||
public static final String JAVA8_MODE_VALUE = "true";
|
||||
public static final String ENSURE_UNIQUE_PARAMS_VALUE = "true";
|
||||
//public static final String SUPPORT_JAVA6 = "true";
|
||||
public static final String USE_BEANVALIDATION = "false";
|
||||
@@ -65,6 +66,7 @@ public class JavaOptionsProvider implements OptionsProvider {
|
||||
.put(CodegenConstants.LOCAL_VARIABLE_PREFIX, LOCAL_PREFIX_VALUE)
|
||||
.put(CodegenConstants.SERIALIZABLE_MODEL, SERIALIZABLE_MODEL_VALUE)
|
||||
.put(JavaClientCodegen.FULL_JAVA_UTIL, FULL_JAVA_UTIL_VALUE)
|
||||
.put(JavaClientCodegen.JAVA8_MODE, JAVA8_MODE_VALUE)
|
||||
.put(CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING, "true")
|
||||
.put(JavaClientCodegen.DATE_LIBRARY, "joda")
|
||||
.put("hideGenerationTimestamp", "true")
|
||||
|
||||
@@ -37,6 +37,7 @@ public class JaxRSServerOptionsProvider implements OptionsProvider {
|
||||
public static final String JAXRS_DEFAULT_LIBRARY_VALUE = "jersey1";
|
||||
public static final String USE_BEANVALIDATION = "true";
|
||||
public static final String ALLOW_UNICODE_IDENTIFIERS_VALUE = "false";
|
||||
public static final String JAVA8_MODE_VALUE = "false";
|
||||
|
||||
|
||||
@Override
|
||||
@@ -81,6 +82,7 @@ public class JaxRSServerOptionsProvider implements OptionsProvider {
|
||||
.put(JavaClientCodegen.FULL_JAVA_UTIL, FULL_JAVA_UTIL_VALUE)
|
||||
.put(CodegenConstants.LIBRARY, JAXRS_DEFAULT_LIBRARY_VALUE)
|
||||
.put(CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING, "true")
|
||||
.put(JavaClientCodegen.JAVA8_MODE, JAVA8_MODE_VALUE)
|
||||
//.put(JavaClientCodegen.DATE_LIBRARY, "joda")
|
||||
.put("hideGenerationTimestamp", "true")
|
||||
.put(JavaCXFServerCodegen.USE_BEANVALIDATION, USE_BEANVALIDATION)
|
||||
|
||||
@@ -134,11 +134,11 @@ dependencies {
|
||||
{{^java8}}
|
||||
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:$jackson_version"
|
||||
compile "joda-time:joda-time:$jodatime_version"
|
||||
compile "com.brsanthu:migbase64:2.2"
|
||||
{{/java8}}
|
||||
{{#supportJava6}}
|
||||
compile "commons-io:commons-io:$commons_io_version"
|
||||
compile "org.apache.commons:commons-lang3:$commons_lang3_version"
|
||||
{{/supportJava6}}
|
||||
compile "com.brsanthu:migbase64:2.2"
|
||||
testCompile "junit:junit:$junit_version"
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ lazy val root = (project in file(".")).
|
||||
{{^java8}}
|
||||
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % "2.7.5",
|
||||
"joda-time" % "joda-time" % "2.9.4",
|
||||
{{/java8}}
|
||||
"com.brsanthu" % "migbase64" % "2.2",
|
||||
{{/java8}}
|
||||
{{#supportJava6}}
|
||||
"org.apache.commons" % "commons-lang3" % "3.5",
|
||||
"commons-io" % "commons-io" % "2.5",
|
||||
|
||||
@@ -242,7 +242,6 @@
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>${jodatime-version}</version>
|
||||
</dependency>
|
||||
{{/java8}}
|
||||
|
||||
<!-- Base64 encoding that works in both JVM and Android -->
|
||||
<dependency>
|
||||
@@ -250,6 +249,8 @@
|
||||
<artifactId>migbase64</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
{{/java8}}
|
||||
|
||||
{{#supportJava6}}
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
|
||||
@@ -94,10 +94,10 @@ if(hasProperty('target') && target == 'android') {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'io.swagger:swagger-annotations:1.5.8'
|
||||
compile 'io.swagger:swagger-annotations:1.5.15'
|
||||
compile 'com.squareup.okhttp:okhttp:2.7.5'
|
||||
compile 'com.squareup.okhttp:logging-interceptor:2.7.5'
|
||||
compile 'com.google.code.gson:gson:2.6.2'
|
||||
compile 'joda-time:joda-time:2.9.3'
|
||||
compile 'com.google.code.gson:gson:2.8.1'
|
||||
compile 'joda-time:joda-time:2.9.9'
|
||||
testCompile 'junit:junit:4.12'
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@ lazy val root = (project in file(".")).
|
||||
publishArtifact in (Compile, packageDoc) := false,
|
||||
resolvers += Resolver.mavenLocal,
|
||||
libraryDependencies ++= Seq(
|
||||
"io.swagger" % "swagger-annotations" % "1.5.8",
|
||||
"io.swagger" % "swagger-annotations" % "1.5.15",
|
||||
"com.squareup.okhttp" % "okhttp" % "2.7.5",
|
||||
"com.squareup.okhttp" % "logging-interceptor" % "2.7.5",
|
||||
"com.google.code.gson" % "gson" % "2.6.2",
|
||||
"joda-time" % "joda-time" % "2.9.3" % "compile",
|
||||
"com.google.code.gson" % "gson" % "2.8.1",
|
||||
"joda-time" % "joda-time" % "2.9.9" % "compile",
|
||||
"junit" % "junit" % "4.12" % "test",
|
||||
"com.novocode" % "junit-interface" % "0.10" % "test"
|
||||
)
|
||||
|
||||
@@ -208,8 +208,8 @@
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<swagger-core-version>1.5.15</swagger-core-version>
|
||||
<okhttp-version>2.7.5</okhttp-version>
|
||||
<gson-version>2.6.2</gson-version>
|
||||
<jodatime-version>2.9.3</jodatime-version>
|
||||
<gson-version>2.8.1</gson-version>
|
||||
<jodatime-version>2.9.9</jodatime-version>
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
<junit-version>4.12</junit-version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
@@ -13,43 +13,24 @@
|
||||
|
||||
package io.swagger.client;
|
||||
|
||||
import com.squareup.okhttp.Call;
|
||||
import com.squareup.okhttp.Callback;
|
||||
import com.squareup.okhttp.OkHttpClient;
|
||||
import com.squareup.okhttp.Request;
|
||||
import com.squareup.okhttp.Response;
|
||||
import com.squareup.okhttp.RequestBody;
|
||||
import com.squareup.okhttp.FormEncodingBuilder;
|
||||
import com.squareup.okhttp.MultipartBuilder;
|
||||
import com.squareup.okhttp.MediaType;
|
||||
import com.squareup.okhttp.Headers;
|
||||
import com.squareup.okhttp.*;
|
||||
import com.squareup.okhttp.internal.http.HttpMethod;
|
||||
import com.squareup.okhttp.logging.HttpLoggingInterceptor;
|
||||
import com.squareup.okhttp.logging.HttpLoggingInterceptor.Level;
|
||||
import okio.BufferedSink;
|
||||
import okio.Okio;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.net.URLConnection;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.KeyStore;
|
||||
import java.security.SecureRandom;
|
||||
@@ -57,22 +38,12 @@ import java.security.cert.Certificate;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.text.ParseException;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.KeyManager;
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import okio.BufferedSink;
|
||||
import okio.Okio;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import io.swagger.client.auth.Authentication;
|
||||
import io.swagger.client.auth.HttpBasicAuth;
|
||||
@@ -80,40 +51,8 @@ import io.swagger.client.auth.ApiKeyAuth;
|
||||
import io.swagger.client.auth.OAuth;
|
||||
|
||||
public class ApiClient {
|
||||
public static final double JAVA_VERSION;
|
||||
public static final boolean IS_ANDROID;
|
||||
public static final int ANDROID_SDK_VERSION;
|
||||
|
||||
static {
|
||||
JAVA_VERSION = Double.parseDouble(System.getProperty("java.specification.version"));
|
||||
boolean isAndroid;
|
||||
try {
|
||||
Class.forName("android.app.Activity");
|
||||
isAndroid = true;
|
||||
} catch (ClassNotFoundException e) {
|
||||
isAndroid = false;
|
||||
}
|
||||
IS_ANDROID = isAndroid;
|
||||
int sdkVersion = 0;
|
||||
if (IS_ANDROID) {
|
||||
try {
|
||||
sdkVersion = Class.forName("android.os.Build$VERSION").getField("SDK_INT").getInt(null);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
sdkVersion = Integer.parseInt((String) Class.forName("android.os.Build$VERSION").getField("SDK").get(null));
|
||||
} catch (Exception e2) { }
|
||||
}
|
||||
}
|
||||
ANDROID_SDK_VERSION = sdkVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* The datetime format to be used when <code>lenientDatetimeFormat</code> is enabled.
|
||||
*/
|
||||
public static final String LENIENT_DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
|
||||
|
||||
private String basePath = "https://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r";
|
||||
private boolean lenientOnJson = false;
|
||||
private boolean debugging = false;
|
||||
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
|
||||
private String tempFolderPath = null;
|
||||
@@ -143,20 +82,7 @@ public class ApiClient {
|
||||
|
||||
verifyingSsl = true;
|
||||
|
||||
json = new JSON(this);
|
||||
|
||||
/*
|
||||
* Use RFC3339 format for date and datetime.
|
||||
* See http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14
|
||||
*/
|
||||
this.dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
// Always use UTC as the default time zone when dealing with date (without time).
|
||||
this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
initDatetimeFormat();
|
||||
|
||||
// Be lenient on datetime formats when parsing datetime from string.
|
||||
// See <code>parseDatetime</code>.
|
||||
this.lenientDatetimeFormat = true;
|
||||
json = new JSON();
|
||||
|
||||
// Set default User-Agent.
|
||||
setUserAgent("Swagger-Codegen/1.0.0/java");
|
||||
@@ -296,138 +222,28 @@ public class ApiClient {
|
||||
}
|
||||
|
||||
public ApiClient setDateFormat(DateFormat dateFormat) {
|
||||
this.dateFormat = dateFormat;
|
||||
this.dateLength = this.dateFormat.format(new Date()).length();
|
||||
this.json.setDateFormat(dateFormat);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DateFormat getDatetimeFormat() {
|
||||
return datetimeFormat;
|
||||
}
|
||||
|
||||
public ApiClient setDatetimeFormat(DateFormat datetimeFormat) {
|
||||
this.datetimeFormat = datetimeFormat;
|
||||
public ApiClient setSqlDateFormat(DateFormat dateFormat) {
|
||||
this.json.setSqlDateFormat(dateFormat);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to allow various ISO 8601 datetime formats when parsing a datetime string.
|
||||
* @see #parseDatetime(String)
|
||||
* @return True if lenientDatetimeFormat flag is set to true
|
||||
*/
|
||||
public boolean isLenientDatetimeFormat() {
|
||||
return lenientDatetimeFormat;
|
||||
}
|
||||
|
||||
public ApiClient setLenientDatetimeFormat(boolean lenientDatetimeFormat) {
|
||||
this.lenientDatetimeFormat = lenientDatetimeFormat;
|
||||
public ApiClient setDateTimeFormat(DateTimeFormatter dateFormat) {
|
||||
this.json.setDateTimeFormat(dateFormat);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the given date string into Date object.
|
||||
* The default <code>dateFormat</code> supports these ISO 8601 date formats:
|
||||
* 2015-08-16
|
||||
* 2015-8-16
|
||||
* @param str String to be parsed
|
||||
* @return Date
|
||||
*/
|
||||
public Date parseDate(String str) {
|
||||
if (str == null)
|
||||
return null;
|
||||
try {
|
||||
return dateFormat.parse(str);
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
public ApiClient setLocalDateFormat(DateTimeFormatter dateFormat) {
|
||||
this.json.setLocalDateFormat(dateFormat);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the given datetime string into Date object.
|
||||
* When lenientDatetimeFormat is enabled, the following ISO 8601 datetime formats are supported:
|
||||
* 2015-08-16T08:20:05Z
|
||||
* 2015-8-16T8:20:05Z
|
||||
* 2015-08-16T08:20:05+00:00
|
||||
* 2015-08-16T08:20:05+0000
|
||||
* 2015-08-16T08:20:05.376Z
|
||||
* 2015-08-16T08:20:05.376+00:00
|
||||
* 2015-08-16T08:20:05.376+00
|
||||
* Note: The 3-digit milli-seconds is optional. Time zone is required and can be in one of
|
||||
* these formats:
|
||||
* Z (same with +0000)
|
||||
* +08:00 (same with +0800)
|
||||
* -02 (same with -0200)
|
||||
* -0200
|
||||
* @see <a href="https://en.wikipedia.org/wiki/ISO_8601">ISO 8601</a>
|
||||
* @param str Date time string to be parsed
|
||||
* @return Date representation of the string
|
||||
*/
|
||||
public Date parseDatetime(String str) {
|
||||
if (str == null)
|
||||
return null;
|
||||
|
||||
DateFormat format;
|
||||
if (lenientDatetimeFormat) {
|
||||
/*
|
||||
* When lenientDatetimeFormat is enabled, normalize the date string
|
||||
* into <code>LENIENT_DATETIME_FORMAT</code> to support various formats
|
||||
* defined by ISO 8601.
|
||||
*/
|
||||
// normalize time zone
|
||||
// trailing "Z": 2015-08-16T08:20:05Z => 2015-08-16T08:20:05+0000
|
||||
str = str.replaceAll("[zZ]\\z", "+0000");
|
||||
// remove colon in time zone: 2015-08-16T08:20:05+00:00 => 2015-08-16T08:20:05+0000
|
||||
str = str.replaceAll("([+-]\\d{2}):(\\d{2})\\z", "$1$2");
|
||||
// expand time zone: 2015-08-16T08:20:05+00 => 2015-08-16T08:20:05+0000
|
||||
str = str.replaceAll("([+-]\\d{2})\\z", "$100");
|
||||
// add milliseconds when missing
|
||||
// 2015-08-16T08:20:05+0000 => 2015-08-16T08:20:05.000+0000
|
||||
str = str.replaceAll("(:\\d{1,2})([+-]\\d{4})\\z", "$1.000$2");
|
||||
format = new SimpleDateFormat(LENIENT_DATETIME_FORMAT);
|
||||
} else {
|
||||
format = this.datetimeFormat;
|
||||
}
|
||||
|
||||
try {
|
||||
return format.parse(str);
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse date or date time in string format into Date object.
|
||||
*
|
||||
* @param str Date time string to be parsed
|
||||
* @return Date representation of the string
|
||||
*/
|
||||
public Date parseDateOrDatetime(String str) {
|
||||
if (str == null)
|
||||
return null;
|
||||
else if (str.length() <= dateLength)
|
||||
return parseDate(str);
|
||||
else
|
||||
return parseDatetime(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the given Date object into string (Date format).
|
||||
*
|
||||
* @param date Date object
|
||||
* @return Formatted date in string representation
|
||||
*/
|
||||
public String formatDate(Date date) {
|
||||
return dateFormat.format(date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the given Date object into string (Datetime format).
|
||||
*
|
||||
* @param date Date object
|
||||
* @return Formatted datetime in string representation
|
||||
*/
|
||||
public String formatDatetime(Date date) {
|
||||
return datetimeFormat.format(date);
|
||||
public ApiClient setLenientOnJson(boolean lenientOnJson) {
|
||||
this.json.setLenientOnJson(lenientOnJson);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -547,26 +363,6 @@ public class ApiClient {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see <a href="https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/stream/JsonReader.html#setLenient(boolean)">setLenient</a>
|
||||
*
|
||||
* @return True if lenientOnJson is enabled, false otherwise.
|
||||
*/
|
||||
public boolean isLenientOnJson() {
|
||||
return lenientOnJson;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set LenientOnJson
|
||||
*
|
||||
* @param lenient True to enable lenientOnJson
|
||||
* @return ApiClient
|
||||
*/
|
||||
public ApiClient setLenientOnJson(boolean lenient) {
|
||||
this.lenientOnJson = lenient;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that whether debugging is enabled for this API client.
|
||||
*
|
||||
@@ -650,8 +446,10 @@ public class ApiClient {
|
||||
public String parameterToString(Object param) {
|
||||
if (param == null) {
|
||||
return "";
|
||||
} else if (param instanceof Date) {
|
||||
return formatDatetime((Date) param);
|
||||
} else if (param instanceof Date || param instanceof DateTime || param instanceof LocalDate) {
|
||||
//Serialize to json string and remove the " enclosing characters
|
||||
String jsonStr = json.serialize(param);
|
||||
return jsonStr.substring(1, jsonStr.length() - 1);
|
||||
} else if (param instanceof Collection) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
for (Object o : (Collection)param) {
|
||||
@@ -667,62 +465,70 @@ public class ApiClient {
|
||||
}
|
||||
|
||||
/**
|
||||
* Format to {@code Pair} objects.
|
||||
* Formats the specified query parameter to a list containing a single {@code Pair} object.
|
||||
*
|
||||
* @param collectionFormat collection format (e.g. csv, tsv)
|
||||
* @param name Name
|
||||
* @param value Value
|
||||
* @return A list of Pair objects
|
||||
* Note that {@code value} must not be a collection.
|
||||
*
|
||||
* @param name The name of the parameter.
|
||||
* @param value The value of the parameter.
|
||||
* @return A list containing a single {@code Pair} object.
|
||||
*/
|
||||
public List<Pair> parameterToPairs(String collectionFormat, String name, Object value){
|
||||
public List<Pair> parameterToPair(String name, Object value) {
|
||||
List<Pair> params = new ArrayList<Pair>();
|
||||
|
||||
// preconditions
|
||||
if (name == null || name.isEmpty() || value == null) return params;
|
||||
if (name == null || name.isEmpty() || value == null || value instanceof Collection) return params;
|
||||
|
||||
Collection valueCollection = null;
|
||||
if (value instanceof Collection) {
|
||||
valueCollection = (Collection) value;
|
||||
} else {
|
||||
params.add(new Pair(name, parameterToString(value)));
|
||||
params.add(new Pair(name, parameterToString(value)));
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the specified collection query parameters to a list of {@code Pair} objects.
|
||||
*
|
||||
* Note that the values of each of the returned Pair objects are percent-encoded.
|
||||
*
|
||||
* @param collectionFormat The collection format of the parameter.
|
||||
* @param name The name of the parameter.
|
||||
* @param value The value of the parameter.
|
||||
* @return A list of {@code Pair} objects.
|
||||
*/
|
||||
public List<Pair> parameterToPairs(String collectionFormat, String name, Collection value) {
|
||||
List<Pair> params = new ArrayList<Pair>();
|
||||
|
||||
// preconditions
|
||||
if (name == null || name.isEmpty() || value == null || value.isEmpty()) {
|
||||
return params;
|
||||
}
|
||||
|
||||
if (valueCollection.isEmpty()){
|
||||
return params;
|
||||
}
|
||||
|
||||
// get the collection format
|
||||
collectionFormat = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv
|
||||
|
||||
// create the params based on the collection format
|
||||
if (collectionFormat.equals("multi")) {
|
||||
for (Object item : valueCollection) {
|
||||
params.add(new Pair(name, parameterToString(item)));
|
||||
if ("multi".equals(collectionFormat)) {
|
||||
for (Object item : value) {
|
||||
params.add(new Pair(name, escapeString(parameterToString(item))));
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
// collectionFormat is assumed to be "csv" by default
|
||||
String delimiter = ",";
|
||||
|
||||
if (collectionFormat.equals("csv")) {
|
||||
delimiter = ",";
|
||||
} else if (collectionFormat.equals("ssv")) {
|
||||
delimiter = " ";
|
||||
} else if (collectionFormat.equals("tsv")) {
|
||||
delimiter = "\t";
|
||||
} else if (collectionFormat.equals("pipes")) {
|
||||
delimiter = "|";
|
||||
// escape all delimiters except commas, which are URI reserved
|
||||
// characters
|
||||
if ("ssv".equals(collectionFormat)) {
|
||||
delimiter = escapeString(" ");
|
||||
} else if ("tsv".equals(collectionFormat)) {
|
||||
delimiter = escapeString("\t");
|
||||
} else if ("pipes".equals(collectionFormat)) {
|
||||
delimiter = escapeString("|");
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder() ;
|
||||
for (Object item : valueCollection) {
|
||||
for (Object item : value) {
|
||||
sb.append(delimiter);
|
||||
sb.append(parameterToString(item));
|
||||
sb.append(escapeString(parameterToString(item)));
|
||||
}
|
||||
|
||||
params.add(new Pair(name, sb.substring(1)));
|
||||
params.add(new Pair(name, sb.substring(delimiter.length())));
|
||||
|
||||
return params;
|
||||
}
|
||||
@@ -1082,6 +888,7 @@ public class ApiClient {
|
||||
* @param path The sub-path of the HTTP URL
|
||||
* @param method The request method, one of "GET", "HEAD", "OPTIONS", "POST", "PUT", "PATCH" and "DELETE"
|
||||
* @param queryParams The query parameters
|
||||
* @param collectionQueryParams The collection query parameters
|
||||
* @param body The request body object
|
||||
* @param headerParams The header parameters
|
||||
* @param formParams The form parameters
|
||||
@@ -1090,8 +897,8 @@ public class ApiClient {
|
||||
* @return The HTTP call
|
||||
* @throws ApiException If fail to serialize the request body object
|
||||
*/
|
||||
public Call buildCall(String path, String method, List<Pair> queryParams, Object body, Map<String, String> headerParams, Map<String, Object> formParams, String[] authNames, ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
|
||||
Request request = buildRequest(path, method, queryParams, body, headerParams, formParams, authNames, progressRequestListener);
|
||||
public Call buildCall(String path, String method, List<Pair> queryParams, List<Pair> collectionQueryParams, Object body, Map<String, String> headerParams, Map<String, Object> formParams, String[] authNames, ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
|
||||
Request request = buildRequest(path, method, queryParams, collectionQueryParams, body, headerParams, formParams, authNames, progressRequestListener);
|
||||
|
||||
return httpClient.newCall(request);
|
||||
}
|
||||
@@ -1102,6 +909,7 @@ public class ApiClient {
|
||||
* @param path The sub-path of the HTTP URL
|
||||
* @param method The request method, one of "GET", "HEAD", "OPTIONS", "POST", "PUT", "PATCH" and "DELETE"
|
||||
* @param queryParams The query parameters
|
||||
* @param collectionQueryParams The collection query parameters
|
||||
* @param body The request body object
|
||||
* @param headerParams The header parameters
|
||||
* @param formParams The form parameters
|
||||
@@ -1110,10 +918,10 @@ public class ApiClient {
|
||||
* @return The HTTP request
|
||||
* @throws ApiException If fail to serialize the request body object
|
||||
*/
|
||||
public Request buildRequest(String path, String method, List<Pair> queryParams, Object body, Map<String, String> headerParams, Map<String, Object> formParams, String[] authNames, ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
|
||||
public Request buildRequest(String path, String method, List<Pair> queryParams, List<Pair> collectionQueryParams, Object body, Map<String, String> headerParams, Map<String, Object> formParams, String[] authNames, ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
|
||||
updateParamsForAuth(authNames, queryParams, headerParams);
|
||||
|
||||
final String url = buildUrl(path, queryParams);
|
||||
final String url = buildUrl(path, queryParams, collectionQueryParams);
|
||||
final Request.Builder reqBuilder = new Request.Builder().url(url);
|
||||
processHeaderParams(headerParams, reqBuilder);
|
||||
|
||||
@@ -1159,9 +967,10 @@ public class ApiClient {
|
||||
*
|
||||
* @param path The sub path
|
||||
* @param queryParams The query parameters
|
||||
* @param collectionQueryParams The collection query parameters
|
||||
* @return The full URL
|
||||
*/
|
||||
public String buildUrl(String path, List<Pair> queryParams) {
|
||||
public String buildUrl(String path, List<Pair> queryParams, List<Pair> collectionQueryParams) {
|
||||
final StringBuilder url = new StringBuilder();
|
||||
url.append(basePath).append(path);
|
||||
|
||||
@@ -1182,6 +991,23 @@ public class ApiClient {
|
||||
}
|
||||
}
|
||||
|
||||
if (collectionQueryParams != null && !collectionQueryParams.isEmpty()) {
|
||||
String prefix = url.toString().contains("?") ? "&" : "?";
|
||||
for (Pair param : collectionQueryParams) {
|
||||
if (param.getValue() != null) {
|
||||
if (prefix != null) {
|
||||
url.append(prefix);
|
||||
prefix = null;
|
||||
} else {
|
||||
url.append("&");
|
||||
}
|
||||
String value = parameterToString(param.getValue());
|
||||
// collection query parameter value already escaped as part of parameterToPairs
|
||||
url.append(escapeString(param.getName())).append("=").append(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
@@ -1269,31 +1095,6 @@ public class ApiClient {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize datetime format according to the current environment, e.g. Java 1.7 and Android.
|
||||
*/
|
||||
private void initDatetimeFormat() {
|
||||
String formatWithTimeZone = null;
|
||||
if (IS_ANDROID) {
|
||||
if (ANDROID_SDK_VERSION >= 18) {
|
||||
// The time zone format "ZZZZZ" is available since Android 4.3 (SDK version 18)
|
||||
formatWithTimeZone = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ";
|
||||
}
|
||||
} else if (JAVA_VERSION >= 1.7) {
|
||||
// The time zone format "XXX" is available since Java 1.7
|
||||
formatWithTimeZone = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX";
|
||||
}
|
||||
if (formatWithTimeZone != null) {
|
||||
this.datetimeFormat = new SimpleDateFormat(formatWithTimeZone);
|
||||
// NOTE: Use the system's default time zone (mainly for datetime formatting).
|
||||
} else {
|
||||
// Use a common format that works across all systems.
|
||||
this.datetimeFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
|
||||
// Always use the UTC time zone as we are using a constant trailing "Z" here.
|
||||
this.datetimeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply SSL related settings to httpClient according to the current values of
|
||||
* verifyingSsl and sslCaCert.
|
||||
|
||||
@@ -15,43 +15,38 @@ package io.swagger.client;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
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 java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Date;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
import org.joda.time.format.ISODateTimeFormat;
|
||||
|
||||
public class JSON {
|
||||
private ApiClient apiClient;
|
||||
private Gson gson;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.ParsePosition;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* JSON constructor.
|
||||
*
|
||||
* @param apiClient An instance of ApiClient
|
||||
*/
|
||||
public JSON(ApiClient apiClient) {
|
||||
this.apiClient = apiClient;
|
||||
public class JSON {
|
||||
private Gson gson;
|
||||
private boolean isLenientOnJson = false;
|
||||
private DateTypeAdapter dateTypeAdapter = new DateTypeAdapter();
|
||||
private SqlDateTypeAdapter sqlDateTypeAdapter = new SqlDateTypeAdapter();
|
||||
private DateTimeTypeAdapter dateTimeTypeAdapter = new DateTimeTypeAdapter();
|
||||
private LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter();
|
||||
|
||||
public JSON() {
|
||||
gson = new GsonBuilder()
|
||||
.registerTypeAdapter(Date.class, new DateAdapter(apiClient))
|
||||
.registerTypeAdapter(DateTime.class, new DateTimeTypeAdapter())
|
||||
.registerTypeAdapter(LocalDate.class, new LocalDateTypeAdapter())
|
||||
.registerTypeAdapter(Date.class, dateTypeAdapter)
|
||||
.registerTypeAdapter(java.sql.Date.class, sqlDateTypeAdapter)
|
||||
.registerTypeAdapter(DateTime.class, dateTimeTypeAdapter)
|
||||
.registerTypeAdapter(LocalDate.class, localDateTypeAdapter)
|
||||
.create();
|
||||
}
|
||||
|
||||
@@ -68,9 +63,16 @@ public class JSON {
|
||||
* Set Gson.
|
||||
*
|
||||
* @param gson Gson
|
||||
* @return JSON
|
||||
*/
|
||||
public void setGson(Gson gson) {
|
||||
public JSON setGson(Gson gson) {
|
||||
this.gson = gson;
|
||||
return this;
|
||||
}
|
||||
|
||||
public JSON setLenientOnJson(boolean lenientOnJson) {
|
||||
isLenientOnJson = lenientOnJson;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,15 +88,15 @@ public class JSON {
|
||||
/**
|
||||
* Deserialize the given JSON string to Java object.
|
||||
*
|
||||
* @param <T> Type
|
||||
* @param body The JSON string
|
||||
* @param <T> Type
|
||||
* @param body The JSON string
|
||||
* @param returnType The type to deserialize into
|
||||
* @return The deserialized Java object
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T deserialize(String body, Type returnType) {
|
||||
try {
|
||||
if (apiClient.isLenientOnJson()) {
|
||||
if (isLenientOnJson) {
|
||||
JsonReader jsonReader = new JsonReader(new StringReader(body));
|
||||
// see https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/stream/JsonReader.html#setLenient(boolean)
|
||||
jsonReader.setLenient(true);
|
||||
@@ -104,122 +106,227 @@ public class JSON {
|
||||
}
|
||||
} catch (JsonParseException e) {
|
||||
// Fallback processing when failed to parse JSON form response body:
|
||||
// return the response body string directly for the String return type;
|
||||
// parse response body into date or datetime for the Date return type.
|
||||
// return the response body string directly for the String return type;
|
||||
if (returnType.equals(String.class))
|
||||
return (T) body;
|
||||
else if (returnType.equals(Date.class))
|
||||
return (T) apiClient.parseDateOrDatetime(body);
|
||||
else throw(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class DateAdapter implements JsonSerializer<Date>, JsonDeserializer<Date> {
|
||||
private final ApiClient apiClient;
|
||||
|
||||
/**
|
||||
* Constructor for DateAdapter
|
||||
*
|
||||
* @param apiClient Api client
|
||||
*/
|
||||
public DateAdapter(ApiClient apiClient) {
|
||||
super();
|
||||
this.apiClient = apiClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize
|
||||
*
|
||||
* @param src Date
|
||||
* @param typeOfSrc Type
|
||||
* @param context Json Serialization Context
|
||||
* @return Json Element
|
||||
*/
|
||||
@Override
|
||||
public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
if (src == null) {
|
||||
return JsonNull.INSTANCE;
|
||||
} else {
|
||||
return new JsonPrimitive(apiClient.formatDatetime(src));
|
||||
else throw (e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize
|
||||
*
|
||||
* @param json Json element
|
||||
* @param date Type
|
||||
* @param context Json Serialization Context
|
||||
* @return Date
|
||||
* @throws JsonParseException if fail to parse
|
||||
* Gson TypeAdapter for Joda DateTime type
|
||||
*/
|
||||
@Override
|
||||
public Date deserialize(JsonElement json, Type date, JsonDeserializationContext context) throws JsonParseException {
|
||||
String str = json.getAsJsonPrimitive().getAsString();
|
||||
try {
|
||||
return apiClient.parseDateOrDatetime(str);
|
||||
} catch (RuntimeException e) {
|
||||
throw new JsonParseException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gson TypeAdapter for Joda DateTime type
|
||||
*/
|
||||
class DateTimeTypeAdapter extends TypeAdapter<DateTime> {
|
||||
|
||||
private final DateTimeFormatter parseFormatter = ISODateTimeFormat.dateOptionalTimeParser();
|
||||
private final DateTimeFormatter printFormatter = ISODateTimeFormat.dateTime();
|
||||
|
||||
@Override
|
||||
public void write(JsonWriter out, DateTime date) throws IOException {
|
||||
if (date == null) {
|
||||
out.nullValue();
|
||||
} else {
|
||||
out.value(printFormatter.print(date));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DateTime read(JsonReader in) throws IOException {
|
||||
switch (in.peek()) {
|
||||
case NULL:
|
||||
in.nextNull();
|
||||
return null;
|
||||
default:
|
||||
String date = in.nextString();
|
||||
return parseFormatter.parseDateTime(date);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gson TypeAdapter for Joda LocalDate type
|
||||
*/
|
||||
class LocalDateTypeAdapter extends TypeAdapter<LocalDate> {
|
||||
|
||||
private final DateTimeFormatter formatter = ISODateTimeFormat.date();
|
||||
|
||||
@Override
|
||||
public void write(JsonWriter out, LocalDate date) throws IOException {
|
||||
if (date == null) {
|
||||
out.nullValue();
|
||||
} else {
|
||||
out.value(formatter.print(date));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDate read(JsonReader in) throws IOException {
|
||||
switch (in.peek()) {
|
||||
case NULL:
|
||||
in.nextNull();
|
||||
return null;
|
||||
default:
|
||||
String date = in.nextString();
|
||||
return formatter.parseLocalDate(date);
|
||||
public static class DateTimeTypeAdapter extends TypeAdapter<DateTime> {
|
||||
|
||||
private final DateTimeFormatter parseFormatter = ISODateTimeFormat.dateOptionalTimeParser();
|
||||
private final DateTimeFormatter printFormatter = ISODateTimeFormat.dateTime();
|
||||
|
||||
public DateTimeTypeAdapter() {
|
||||
this(ISODateTimeFormat.dateTime().withOffsetParsed());
|
||||
}
|
||||
|
||||
public DateTimeTypeAdapter(DateTimeFormatter formatter) {
|
||||
this.formatter = formatter;
|
||||
}
|
||||
|
||||
public void setFormat(DateTimeFormatter dateFormat) {
|
||||
this.formatter = dateFormat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(JsonWriter out, DateTime date) throws IOException {
|
||||
if (date == null) {
|
||||
out.nullValue();
|
||||
} else {
|
||||
out.value(printFormatter.print(date));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DateTime read(JsonReader in) throws IOException {
|
||||
switch (in.peek()) {
|
||||
case NULL:
|
||||
in.nextNull();
|
||||
return null;
|
||||
default:
|
||||
String date = in.nextString();
|
||||
return parseFormatter.parseDateTime(date);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gson TypeAdapter for Joda LocalDate type
|
||||
*/
|
||||
public class LocalDateTypeAdapter extends TypeAdapter<LocalDate> {
|
||||
|
||||
private DateTimeFormatter formatter;
|
||||
|
||||
public LocalDateTypeAdapter() {
|
||||
this(ISODateTimeFormat.date());
|
||||
}
|
||||
|
||||
public LocalDateTypeAdapter(DateTimeFormatter formatter) {
|
||||
this.formatter = formatter;
|
||||
}
|
||||
|
||||
public void setFormat(DateTimeFormatter dateFormat) {
|
||||
this.formatter = dateFormat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(JsonWriter out, LocalDate date) throws IOException {
|
||||
if (date == null) {
|
||||
out.nullValue();
|
||||
} else {
|
||||
out.value(formatter.print(date));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDate read(JsonReader in) throws IOException {
|
||||
switch (in.peek()) {
|
||||
case NULL:
|
||||
in.nextNull();
|
||||
return null;
|
||||
default:
|
||||
String date = in.nextString();
|
||||
return formatter.parseLocalDate(date);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public JSON setDateTimeFormat(DateTimeFormatter dateFormat) {
|
||||
dateTimeTypeAdapter.setFormat(dateFormat);
|
||||
return this;
|
||||
}
|
||||
|
||||
public JSON setLocalDateFormat(DateTimeFormatter dateFormat) {
|
||||
localDateTypeAdapter.setFormat(dateFormat);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gson TypeAdapter for java.sql.Date type
|
||||
* If the dateFormat is null, a simple "yyyy-MM-dd" format will be used
|
||||
* (more efficient than SimpleDateFormat).
|
||||
*/
|
||||
public static class SqlDateTypeAdapter extends TypeAdapter<java.sql.Date> {
|
||||
|
||||
private DateFormat dateFormat;
|
||||
|
||||
public SqlDateTypeAdapter() {
|
||||
}
|
||||
|
||||
public SqlDateTypeAdapter(DateFormat dateFormat) {
|
||||
this.dateFormat = dateFormat;
|
||||
}
|
||||
|
||||
public void setFormat(DateFormat dateFormat) {
|
||||
this.dateFormat = dateFormat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(JsonWriter out, java.sql.Date date) throws IOException {
|
||||
if (date == null) {
|
||||
out.nullValue();
|
||||
} else {
|
||||
String value;
|
||||
if (dateFormat != null) {
|
||||
value = dateFormat.format(date);
|
||||
} else {
|
||||
value = date.toString();
|
||||
}
|
||||
out.value(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.sql.Date read(JsonReader in) throws IOException {
|
||||
switch (in.peek()) {
|
||||
case NULL:
|
||||
in.nextNull();
|
||||
return null;
|
||||
default:
|
||||
String date = in.nextString();
|
||||
try {
|
||||
if (dateFormat != null) {
|
||||
return new java.sql.Date(dateFormat.parse(date).getTime());
|
||||
}
|
||||
return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime());
|
||||
} catch (ParseException e) {
|
||||
throw new JsonParseException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gson TypeAdapter for java.util.Date type
|
||||
* If the dateFormat is null, ISO8601Utils will be used.
|
||||
*/
|
||||
public static class DateTypeAdapter extends TypeAdapter<Date> {
|
||||
|
||||
private DateFormat dateFormat;
|
||||
|
||||
public DateTypeAdapter() {
|
||||
}
|
||||
|
||||
public DateTypeAdapter(DateFormat dateFormat) {
|
||||
this.dateFormat = dateFormat;
|
||||
}
|
||||
|
||||
public void setFormat(DateFormat dateFormat) {
|
||||
this.dateFormat = dateFormat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(JsonWriter out, Date date) throws IOException {
|
||||
if (date == null) {
|
||||
out.nullValue();
|
||||
} else {
|
||||
String value;
|
||||
if (dateFormat != null) {
|
||||
value = dateFormat.format(date);
|
||||
} else {
|
||||
value = ISO8601Utils.format(date, true);
|
||||
}
|
||||
out.value(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date read(JsonReader in) throws IOException {
|
||||
try {
|
||||
switch (in.peek()) {
|
||||
case NULL:
|
||||
in.nextNull();
|
||||
return null;
|
||||
default:
|
||||
String date = in.nextString();
|
||||
try {
|
||||
if (dateFormat != null) {
|
||||
return dateFormat.parse(date);
|
||||
}
|
||||
return ISO8601Utils.parse(date, new ParsePosition(0));
|
||||
} catch (ParseException e) {
|
||||
throw new JsonParseException(e);
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new JsonParseException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public JSON setDateFormat(DateFormat dateFormat) {
|
||||
dateTypeAdapter.setFormat(dateFormat);
|
||||
return this;
|
||||
}
|
||||
|
||||
public JSON setSqlDateFormat(DateFormat dateFormat) {
|
||||
sqlDateTypeAdapter.setFormat(dateFormat);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@ public class FakeApi {
|
||||
String localVarPath = "/fake";
|
||||
|
||||
List<Pair> localVarQueryParams = new ArrayList<Pair>();
|
||||
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
|
||||
|
||||
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
|
||||
|
||||
@@ -100,7 +101,7 @@ public class FakeApi {
|
||||
}
|
||||
|
||||
String[] localVarAuthNames = new String[] { };
|
||||
return apiClient.buildCall(localVarPath, "PUT", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
|
||||
return apiClient.buildCall(localVarPath, "PUT", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
|
||||
@@ -1 +1 @@
|
||||
2.3.0-SNAPSHOT
|
||||
2.2.3-SNAPSHOT
|
||||
@@ -96,7 +96,6 @@ if(hasProperty('target') && target == 'android') {
|
||||
ext {
|
||||
swagger_annotations_version = "1.5.9"
|
||||
jackson_version = "2.8.7"
|
||||
threepane_version = "2.6.4"
|
||||
feign_version = "9.4.0"
|
||||
feign_form_version = "2.1.0"
|
||||
junit_version = "4.12"
|
||||
@@ -112,7 +111,7 @@ dependencies {
|
||||
compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
|
||||
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
|
||||
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
|
||||
compile "com.github.joschi.jackson:jackson-datatype-threetenbp:$threepane_version"
|
||||
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:$jackson_version"
|
||||
compile "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version"
|
||||
compile "com.brsanthu:migbase64:2.2"
|
||||
testCompile "junit:junit:$junit_version"
|
||||
|
||||
@@ -213,9 +213,9 @@
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.joschi.jackson</groupId>
|
||||
<artifactId>jackson-datatype-threetenbp</artifactId>
|
||||
<version>${jackson-threetenbp-version}</version>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-joda</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.oltu.oauth2</groupId>
|
||||
@@ -250,8 +250,7 @@
|
||||
<swagger-core-version>1.5.15</swagger-core-version>
|
||||
<feign-version>9.4.0</feign-version>
|
||||
<feign-form-version>2.1.0</feign-form-version>
|
||||
<jackson-version>2.8.9</jackson-version>
|
||||
<jackson-threetenbp-version>2.6.4</jackson-threetenbp-version>
|
||||
<jackson-version>2.8.7</jackson-version>
|
||||
<junit-version>4.12</junit-version>
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
<oltu-version>1.0.1</oltu-version>
|
||||
|
||||
@@ -5,12 +5,11 @@ import java.util.Map;
|
||||
|
||||
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.AuthenticationRequestBuilder;
|
||||
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder;
|
||||
import org.threeten.bp.*;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.ThreeTenModule;
|
||||
import com.fasterxml.jackson.datatype.joda.JodaModule;
|
||||
|
||||
import feign.Feign;
|
||||
import feign.RequestInterceptor;
|
||||
@@ -136,11 +135,7 @@ public class ApiClient {
|
||||
objectMapper.disable(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE);
|
||||
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
objectMapper.setDateFormat(new RFC3339DateFormat());
|
||||
ThreeTenModule module = new ThreeTenModule();
|
||||
module.addDeserializer(Instant.class, CustomInstantDeserializer.INSTANT);
|
||||
module.addDeserializer(OffsetDateTime.class, CustomInstantDeserializer.OFFSET_DATE_TIME);
|
||||
module.addDeserializer(ZonedDateTime.class, CustomInstantDeserializer.ZONED_DATE_TIME);
|
||||
objectMapper.registerModule(module);
|
||||
objectMapper.registerModule(new JodaModule());
|
||||
return objectMapper;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,232 +0,0 @@
|
||||
package io.swagger.client;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.DateTimeUtils;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.DecimalUtils;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.deser.ThreeTenDateTimeDeserializerBase;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.function.BiFunction;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.function.Function;
|
||||
import org.threeten.bp.DateTimeException;
|
||||
import org.threeten.bp.Instant;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.threeten.bp.ZoneId;
|
||||
import org.threeten.bp.ZonedDateTime;
|
||||
import org.threeten.bp.format.DateTimeFormatter;
|
||||
import org.threeten.bp.temporal.Temporal;
|
||||
import org.threeten.bp.temporal.TemporalAccessor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* Deserializer for ThreeTen temporal {@link Instant}s, {@link OffsetDateTime}, and {@link ZonedDateTime}s.
|
||||
* Adapted from the jackson threetenbp InstantDeserializer to add support for deserializing rfc822 format.
|
||||
*
|
||||
* @author Nick Williams
|
||||
*/
|
||||
public class CustomInstantDeserializer<T extends Temporal>
|
||||
extends ThreeTenDateTimeDeserializerBase<T> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final CustomInstantDeserializer<Instant> INSTANT = new CustomInstantDeserializer<Instant>(
|
||||
Instant.class, DateTimeFormatter.ISO_INSTANT,
|
||||
new Function<TemporalAccessor, Instant>() {
|
||||
@Override
|
||||
public Instant apply(TemporalAccessor temporalAccessor) {
|
||||
return Instant.from(temporalAccessor);
|
||||
}
|
||||
},
|
||||
new Function<FromIntegerArguments, Instant>() {
|
||||
@Override
|
||||
public Instant apply(FromIntegerArguments a) {
|
||||
return Instant.ofEpochMilli(a.value);
|
||||
}
|
||||
},
|
||||
new Function<FromDecimalArguments, Instant>() {
|
||||
@Override
|
||||
public Instant apply(FromDecimalArguments a) {
|
||||
return Instant.ofEpochSecond(a.integer, a.fraction);
|
||||
}
|
||||
},
|
||||
null
|
||||
);
|
||||
|
||||
public static final CustomInstantDeserializer<OffsetDateTime> OFFSET_DATE_TIME = new CustomInstantDeserializer<OffsetDateTime>(
|
||||
OffsetDateTime.class, DateTimeFormatter.ISO_OFFSET_DATE_TIME,
|
||||
new Function<TemporalAccessor, OffsetDateTime>() {
|
||||
@Override
|
||||
public OffsetDateTime apply(TemporalAccessor temporalAccessor) {
|
||||
return OffsetDateTime.from(temporalAccessor);
|
||||
}
|
||||
},
|
||||
new Function<FromIntegerArguments, OffsetDateTime>() {
|
||||
@Override
|
||||
public OffsetDateTime apply(FromIntegerArguments a) {
|
||||
return OffsetDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId);
|
||||
}
|
||||
},
|
||||
new Function<FromDecimalArguments, OffsetDateTime>() {
|
||||
@Override
|
||||
public OffsetDateTime apply(FromDecimalArguments a) {
|
||||
return OffsetDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId);
|
||||
}
|
||||
},
|
||||
new BiFunction<OffsetDateTime, ZoneId, OffsetDateTime>() {
|
||||
@Override
|
||||
public OffsetDateTime apply(OffsetDateTime d, ZoneId z) {
|
||||
return d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime()));
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
public static final CustomInstantDeserializer<ZonedDateTime> ZONED_DATE_TIME = new CustomInstantDeserializer<ZonedDateTime>(
|
||||
ZonedDateTime.class, DateTimeFormatter.ISO_ZONED_DATE_TIME,
|
||||
new Function<TemporalAccessor, ZonedDateTime>() {
|
||||
@Override
|
||||
public ZonedDateTime apply(TemporalAccessor temporalAccessor) {
|
||||
return ZonedDateTime.from(temporalAccessor);
|
||||
}
|
||||
},
|
||||
new Function<FromIntegerArguments, ZonedDateTime>() {
|
||||
@Override
|
||||
public ZonedDateTime apply(FromIntegerArguments a) {
|
||||
return ZonedDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId);
|
||||
}
|
||||
},
|
||||
new Function<FromDecimalArguments, ZonedDateTime>() {
|
||||
@Override
|
||||
public ZonedDateTime apply(FromDecimalArguments a) {
|
||||
return ZonedDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId);
|
||||
}
|
||||
},
|
||||
new BiFunction<ZonedDateTime, ZoneId, ZonedDateTime>() {
|
||||
@Override
|
||||
public ZonedDateTime apply(ZonedDateTime zonedDateTime, ZoneId zoneId) {
|
||||
return zonedDateTime.withZoneSameInstant(zoneId);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
protected final Function<FromIntegerArguments, T> fromMilliseconds;
|
||||
|
||||
protected final Function<FromDecimalArguments, T> fromNanoseconds;
|
||||
|
||||
protected final Function<TemporalAccessor, T> parsedToValue;
|
||||
|
||||
protected final BiFunction<T, ZoneId, T> adjust;
|
||||
|
||||
protected CustomInstantDeserializer(Class<T> supportedType,
|
||||
DateTimeFormatter parser,
|
||||
Function<TemporalAccessor, T> parsedToValue,
|
||||
Function<FromIntegerArguments, T> fromMilliseconds,
|
||||
Function<FromDecimalArguments, T> fromNanoseconds,
|
||||
BiFunction<T, ZoneId, T> adjust) {
|
||||
super(supportedType, parser);
|
||||
this.parsedToValue = parsedToValue;
|
||||
this.fromMilliseconds = fromMilliseconds;
|
||||
this.fromNanoseconds = fromNanoseconds;
|
||||
this.adjust = adjust == null ? new BiFunction<T, ZoneId, T>() {
|
||||
@Override
|
||||
public T apply(T t, ZoneId zoneId) {
|
||||
return t;
|
||||
}
|
||||
} : adjust;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected CustomInstantDeserializer(CustomInstantDeserializer<T> base, DateTimeFormatter f) {
|
||||
super((Class<T>) base.handledType(), f);
|
||||
parsedToValue = base.parsedToValue;
|
||||
fromMilliseconds = base.fromMilliseconds;
|
||||
fromNanoseconds = base.fromNanoseconds;
|
||||
adjust = base.adjust;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonDeserializer<T> withDateFormat(DateTimeFormatter dtf) {
|
||||
if (dtf == _formatter) {
|
||||
return this;
|
||||
}
|
||||
return new CustomInstantDeserializer<T>(this, dtf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T deserialize(JsonParser parser, DeserializationContext context) throws IOException {
|
||||
//NOTE: Timestamps contain no timezone info, and are always in configured TZ. Only
|
||||
//string values have to be adjusted to the configured TZ.
|
||||
switch (parser.getCurrentTokenId()) {
|
||||
case JsonTokenId.ID_NUMBER_FLOAT: {
|
||||
BigDecimal value = parser.getDecimalValue();
|
||||
long seconds = value.longValue();
|
||||
int nanoseconds = DecimalUtils.extractNanosecondDecimal(value, seconds);
|
||||
return fromNanoseconds.apply(new FromDecimalArguments(
|
||||
seconds, nanoseconds, getZone(context)));
|
||||
}
|
||||
|
||||
case JsonTokenId.ID_NUMBER_INT: {
|
||||
long timestamp = parser.getLongValue();
|
||||
if (context.isEnabled(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS)) {
|
||||
return this.fromNanoseconds.apply(new FromDecimalArguments(
|
||||
timestamp, 0, this.getZone(context)
|
||||
));
|
||||
}
|
||||
return this.fromMilliseconds.apply(new FromIntegerArguments(
|
||||
timestamp, this.getZone(context)
|
||||
));
|
||||
}
|
||||
|
||||
case JsonTokenId.ID_STRING: {
|
||||
String string = parser.getText().trim();
|
||||
if (string.length() == 0) {
|
||||
return null;
|
||||
}
|
||||
if (string.endsWith("+0000")) {
|
||||
string = string.substring(0, string.length() - 5) + "Z";
|
||||
}
|
||||
T value;
|
||||
try {
|
||||
TemporalAccessor acc = _formatter.parse(string);
|
||||
value = parsedToValue.apply(acc);
|
||||
if (context.isEnabled(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)) {
|
||||
return adjust.apply(value, this.getZone(context));
|
||||
}
|
||||
} catch (DateTimeException e) {
|
||||
throw _peelDTE(e);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
throw context.mappingException("Expected type float, integer, or string.");
|
||||
}
|
||||
|
||||
private ZoneId getZone(DeserializationContext context) {
|
||||
// Instants are always in UTC, so don't waste compute cycles
|
||||
return (_valueClass == Instant.class) ? null : DateTimeUtils.timeZoneToZoneId(context.getTimeZone());
|
||||
}
|
||||
|
||||
private static class FromIntegerArguments {
|
||||
public final long value;
|
||||
public final ZoneId zoneId;
|
||||
|
||||
private FromIntegerArguments(long value, ZoneId zoneId) {
|
||||
this.value = value;
|
||||
this.zoneId = zoneId;
|
||||
}
|
||||
}
|
||||
|
||||
private static class FromDecimalArguments {
|
||||
public final long integer;
|
||||
public final int fraction;
|
||||
public final ZoneId zoneId;
|
||||
|
||||
private FromDecimalArguments(long integer, int fraction, ZoneId zoneId) {
|
||||
this.integer = integer;
|
||||
this.fraction = fraction;
|
||||
this.zoneId = zoneId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,8 @@ import io.swagger.client.EncodingUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import io.swagger.client.model.Client;
|
||||
import org.threeten.bp.LocalDate;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
import io.swagger.client.model.OuterComposite;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -107,7 +107,7 @@ public interface FakeApi extends ApiClient.Api {
|
||||
"Content-Type: application/xml; charset=utf-8",
|
||||
"Accept: application/xml; charset=utf-8,application/json; charset=utf-8",
|
||||
})
|
||||
void testEndpointParameters(@Param("number") BigDecimal number, @Param("_double") Double _double, @Param("patternWithoutDelimiter") String patternWithoutDelimiter, @Param("_byte") byte[] _byte, @Param("integer") Integer integer, @Param("int32") Integer int32, @Param("int64") Long int64, @Param("_float") Float _float, @Param("string") String string, @Param("binary") byte[] binary, @Param("date") LocalDate date, @Param("dateTime") OffsetDateTime dateTime, @Param("password") String password, @Param("paramCallback") String paramCallback);
|
||||
void testEndpointParameters(@Param("number") BigDecimal number, @Param("_double") Double _double, @Param("patternWithoutDelimiter") String patternWithoutDelimiter, @Param("_byte") byte[] _byte, @Param("integer") Integer integer, @Param("int32") Integer int32, @Param("int64") Long int64, @Param("_float") Float _float, @Param("string") String string, @Param("binary") byte[] binary, @Param("date") LocalDate date, @Param("dateTime") DateTime dateTime, @Param("password") String password, @Param("paramCallback") String paramCallback);
|
||||
|
||||
/**
|
||||
* To test enum parameters
|
||||
|
||||
@@ -21,8 +21,8 @@ import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.UUID;
|
||||
import org.threeten.bp.LocalDate;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
|
||||
/**
|
||||
* FormatTest
|
||||
@@ -60,7 +60,7 @@ public class FormatTest {
|
||||
private LocalDate date = null;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
private OffsetDateTime dateTime = null;
|
||||
private DateTime dateTime = null;
|
||||
|
||||
@JsonProperty("uuid")
|
||||
private UUID uuid = null;
|
||||
@@ -258,7 +258,7 @@ public class FormatTest {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public FormatTest dateTime(OffsetDateTime dateTime) {
|
||||
public FormatTest dateTime(DateTime dateTime) {
|
||||
this.dateTime = dateTime;
|
||||
return this;
|
||||
}
|
||||
@@ -268,11 +268,11 @@ public class FormatTest {
|
||||
* @return dateTime
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public OffsetDateTime getDateTime() {
|
||||
public DateTime getDateTime() {
|
||||
return dateTime;
|
||||
}
|
||||
|
||||
public void setDateTime(OffsetDateTime dateTime) {
|
||||
public void setDateTime(DateTime dateTime) {
|
||||
this.dateTime = dateTime;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/**
|
||||
* MixedPropertiesAndAdditionalPropertiesClass
|
||||
@@ -35,7 +35,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
|
||||
private UUID uuid = null;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
private OffsetDateTime dateTime = null;
|
||||
private DateTime dateTime = null;
|
||||
|
||||
@JsonProperty("map")
|
||||
private Map<String, Animal> map = null;
|
||||
@@ -58,7 +58,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public MixedPropertiesAndAdditionalPropertiesClass dateTime(OffsetDateTime dateTime) {
|
||||
public MixedPropertiesAndAdditionalPropertiesClass dateTime(DateTime dateTime) {
|
||||
this.dateTime = dateTime;
|
||||
return this;
|
||||
}
|
||||
@@ -68,11 +68,11 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
|
||||
* @return dateTime
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public OffsetDateTime getDateTime() {
|
||||
public DateTime getDateTime() {
|
||||
return dateTime;
|
||||
}
|
||||
|
||||
public void setDateTime(OffsetDateTime dateTime) {
|
||||
public void setDateTime(DateTime dateTime) {
|
||||
this.dateTime = dateTime;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/**
|
||||
* Order
|
||||
@@ -36,7 +36,7 @@ public class Order {
|
||||
private Integer quantity = null;
|
||||
|
||||
@JsonProperty("shipDate")
|
||||
private OffsetDateTime shipDate = null;
|
||||
private DateTime shipDate = null;
|
||||
|
||||
/**
|
||||
* Order Status
|
||||
@@ -135,7 +135,7 @@ public class Order {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public Order shipDate(OffsetDateTime shipDate) {
|
||||
public Order shipDate(DateTime shipDate) {
|
||||
this.shipDate = shipDate;
|
||||
return this;
|
||||
}
|
||||
@@ -145,11 +145,11 @@ public class Order {
|
||||
* @return shipDate
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public OffsetDateTime getShipDate() {
|
||||
public DateTime getShipDate() {
|
||||
return shipDate;
|
||||
}
|
||||
|
||||
public void setShipDate(OffsetDateTime shipDate) {
|
||||
public void setShipDate(DateTime shipDate) {
|
||||
this.shipDate = shipDate;
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
2.3.0-SNAPSHOT
|
||||
2.2.3-SNAPSHOT
|
||||
@@ -95,7 +95,7 @@ if(hasProperty('target') && target == 'android') {
|
||||
|
||||
ext {
|
||||
swagger_annotations_version = "1.5.15"
|
||||
jackson_version = "2.6.4"
|
||||
jackson_version = "2.8.9"
|
||||
jersey_version = "1.19.4"
|
||||
jodatime_version = "2.9.9"
|
||||
junit_version = "4.12"
|
||||
@@ -109,7 +109,7 @@ dependencies {
|
||||
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
|
||||
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
|
||||
compile "com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:$jackson_version"
|
||||
compile "com.github.joschi.jackson:jackson-datatype-threetenbp:$jackson_version",
|
||||
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:$jackson_version",
|
||||
compile "com.brsanthu:migbase64:2.2"
|
||||
testCompile "junit:junit:$junit_version"
|
||||
}
|
||||
|
||||
@@ -275,7 +275,7 @@ Float _float = 3.4F; // Float | None
|
||||
String string = "string_example"; // String | None
|
||||
byte[] binary = B; // byte[] | None
|
||||
LocalDate date = new LocalDate(); // LocalDate | None
|
||||
OffsetDateTime dateTime = new OffsetDateTime(); // OffsetDateTime | None
|
||||
DateTime dateTime = new DateTime(); // DateTime | None
|
||||
String password = "password_example"; // String | None
|
||||
String paramCallback = "paramCallback_example"; // String | None
|
||||
try {
|
||||
@@ -301,7 +301,7 @@ Name | Type | Description | Notes
|
||||
**string** | **String**| None | [optional]
|
||||
**binary** | **byte[]**| None | [optional]
|
||||
**date** | **LocalDate**| None | [optional]
|
||||
**dateTime** | **OffsetDateTime**| None | [optional]
|
||||
**dateTime** | **DateTime**| None | [optional]
|
||||
**password** | **String**| None | [optional]
|
||||
**paramCallback** | **String**| None | [optional]
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ Name | Type | Description | Notes
|
||||
**_byte** | **byte[]** | |
|
||||
**binary** | **byte[]** | | [optional]
|
||||
**date** | [**LocalDate**](LocalDate.md) | |
|
||||
**dateTime** | [**OffsetDateTime**](OffsetDateTime.md) | | [optional]
|
||||
**dateTime** | [**DateTime**](DateTime.md) | | [optional]
|
||||
**uuid** | [**UUID**](UUID.md) | | [optional]
|
||||
**password** | **String** | |
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**uuid** | [**UUID**](UUID.md) | | [optional]
|
||||
**dateTime** | [**OffsetDateTime**](OffsetDateTime.md) | | [optional]
|
||||
**dateTime** | [**DateTime**](DateTime.md) | | [optional]
|
||||
**map** | [**Map<String, Animal>**](Animal.md) | | [optional]
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ Name | Type | Description | Notes
|
||||
**id** | **Long** | | [optional]
|
||||
**petId** | **Long** | | [optional]
|
||||
**quantity** | **Integer** | | [optional]
|
||||
**shipDate** | [**OffsetDateTime**](OffsetDateTime.md) | | [optional]
|
||||
**shipDate** | [**DateTime**](DateTime.md) | | [optional]
|
||||
**status** | [**StatusEnum**](#StatusEnum) | Order Status | [optional]
|
||||
**complete** | **Boolean** | | [optional]
|
||||
|
||||
|
||||
@@ -218,8 +218,8 @@
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.joschi.jackson</groupId>
|
||||
<artifactId>jackson-datatype-threetenbp</artifactId>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-joda</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
|
||||
@@ -244,7 +244,7 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<swagger-annotations-version>1.5.15</swagger-annotations-version>
|
||||
<jersey-version>1.19.4</jersey-version>
|
||||
<jackson-version>2.6.4</jackson-version>
|
||||
<jackson-version>2.7.5</jackson-version>
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
<junit-version>4.12</junit-version>
|
||||
</properties>
|
||||
|
||||
@@ -12,11 +12,9 @@
|
||||
|
||||
package io.swagger.client;
|
||||
|
||||
import org.threeten.bp.*;
|
||||
|
||||
import com.fasterxml.jackson.annotation.*;
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.ThreeTenModule;
|
||||
import com.fasterxml.jackson.datatype.joda.JodaModule;
|
||||
import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
|
||||
|
||||
import com.sun.jersey.api.client.Client;
|
||||
@@ -80,11 +78,7 @@ public class ApiClient {
|
||||
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
objectMapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
|
||||
objectMapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
|
||||
ThreeTenModule module = new ThreeTenModule();
|
||||
module.addDeserializer(Instant.class, CustomInstantDeserializer.INSTANT);
|
||||
module.addDeserializer(OffsetDateTime.class, CustomInstantDeserializer.OFFSET_DATE_TIME);
|
||||
module.addDeserializer(ZonedDateTime.class, CustomInstantDeserializer.ZONED_DATE_TIME);
|
||||
objectMapper.registerModule(module);
|
||||
objectMapper.registerModule(new JodaModule());
|
||||
objectMapper.setDateFormat(ApiClient.buildDefaultDateFormat());
|
||||
|
||||
dateFormat = ApiClient.buildDefaultDateFormat();
|
||||
|
||||
@@ -1,232 +0,0 @@
|
||||
package io.swagger.client;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.DateTimeUtils;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.DecimalUtils;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.deser.ThreeTenDateTimeDeserializerBase;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.function.BiFunction;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.function.Function;
|
||||
import org.threeten.bp.DateTimeException;
|
||||
import org.threeten.bp.Instant;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.threeten.bp.ZoneId;
|
||||
import org.threeten.bp.ZonedDateTime;
|
||||
import org.threeten.bp.format.DateTimeFormatter;
|
||||
import org.threeten.bp.temporal.Temporal;
|
||||
import org.threeten.bp.temporal.TemporalAccessor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* Deserializer for ThreeTen temporal {@link Instant}s, {@link OffsetDateTime}, and {@link ZonedDateTime}s.
|
||||
* Adapted from the jackson threetenbp InstantDeserializer to add support for deserializing rfc822 format.
|
||||
*
|
||||
* @author Nick Williams
|
||||
*/
|
||||
public class CustomInstantDeserializer<T extends Temporal>
|
||||
extends ThreeTenDateTimeDeserializerBase<T> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final CustomInstantDeserializer<Instant> INSTANT = new CustomInstantDeserializer<Instant>(
|
||||
Instant.class, DateTimeFormatter.ISO_INSTANT,
|
||||
new Function<TemporalAccessor, Instant>() {
|
||||
@Override
|
||||
public Instant apply(TemporalAccessor temporalAccessor) {
|
||||
return Instant.from(temporalAccessor);
|
||||
}
|
||||
},
|
||||
new Function<FromIntegerArguments, Instant>() {
|
||||
@Override
|
||||
public Instant apply(FromIntegerArguments a) {
|
||||
return Instant.ofEpochMilli(a.value);
|
||||
}
|
||||
},
|
||||
new Function<FromDecimalArguments, Instant>() {
|
||||
@Override
|
||||
public Instant apply(FromDecimalArguments a) {
|
||||
return Instant.ofEpochSecond(a.integer, a.fraction);
|
||||
}
|
||||
},
|
||||
null
|
||||
);
|
||||
|
||||
public static final CustomInstantDeserializer<OffsetDateTime> OFFSET_DATE_TIME = new CustomInstantDeserializer<OffsetDateTime>(
|
||||
OffsetDateTime.class, DateTimeFormatter.ISO_OFFSET_DATE_TIME,
|
||||
new Function<TemporalAccessor, OffsetDateTime>() {
|
||||
@Override
|
||||
public OffsetDateTime apply(TemporalAccessor temporalAccessor) {
|
||||
return OffsetDateTime.from(temporalAccessor);
|
||||
}
|
||||
},
|
||||
new Function<FromIntegerArguments, OffsetDateTime>() {
|
||||
@Override
|
||||
public OffsetDateTime apply(FromIntegerArguments a) {
|
||||
return OffsetDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId);
|
||||
}
|
||||
},
|
||||
new Function<FromDecimalArguments, OffsetDateTime>() {
|
||||
@Override
|
||||
public OffsetDateTime apply(FromDecimalArguments a) {
|
||||
return OffsetDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId);
|
||||
}
|
||||
},
|
||||
new BiFunction<OffsetDateTime, ZoneId, OffsetDateTime>() {
|
||||
@Override
|
||||
public OffsetDateTime apply(OffsetDateTime d, ZoneId z) {
|
||||
return d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime()));
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
public static final CustomInstantDeserializer<ZonedDateTime> ZONED_DATE_TIME = new CustomInstantDeserializer<ZonedDateTime>(
|
||||
ZonedDateTime.class, DateTimeFormatter.ISO_ZONED_DATE_TIME,
|
||||
new Function<TemporalAccessor, ZonedDateTime>() {
|
||||
@Override
|
||||
public ZonedDateTime apply(TemporalAccessor temporalAccessor) {
|
||||
return ZonedDateTime.from(temporalAccessor);
|
||||
}
|
||||
},
|
||||
new Function<FromIntegerArguments, ZonedDateTime>() {
|
||||
@Override
|
||||
public ZonedDateTime apply(FromIntegerArguments a) {
|
||||
return ZonedDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId);
|
||||
}
|
||||
},
|
||||
new Function<FromDecimalArguments, ZonedDateTime>() {
|
||||
@Override
|
||||
public ZonedDateTime apply(FromDecimalArguments a) {
|
||||
return ZonedDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId);
|
||||
}
|
||||
},
|
||||
new BiFunction<ZonedDateTime, ZoneId, ZonedDateTime>() {
|
||||
@Override
|
||||
public ZonedDateTime apply(ZonedDateTime zonedDateTime, ZoneId zoneId) {
|
||||
return zonedDateTime.withZoneSameInstant(zoneId);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
protected final Function<FromIntegerArguments, T> fromMilliseconds;
|
||||
|
||||
protected final Function<FromDecimalArguments, T> fromNanoseconds;
|
||||
|
||||
protected final Function<TemporalAccessor, T> parsedToValue;
|
||||
|
||||
protected final BiFunction<T, ZoneId, T> adjust;
|
||||
|
||||
protected CustomInstantDeserializer(Class<T> supportedType,
|
||||
DateTimeFormatter parser,
|
||||
Function<TemporalAccessor, T> parsedToValue,
|
||||
Function<FromIntegerArguments, T> fromMilliseconds,
|
||||
Function<FromDecimalArguments, T> fromNanoseconds,
|
||||
BiFunction<T, ZoneId, T> adjust) {
|
||||
super(supportedType, parser);
|
||||
this.parsedToValue = parsedToValue;
|
||||
this.fromMilliseconds = fromMilliseconds;
|
||||
this.fromNanoseconds = fromNanoseconds;
|
||||
this.adjust = adjust == null ? new BiFunction<T, ZoneId, T>() {
|
||||
@Override
|
||||
public T apply(T t, ZoneId zoneId) {
|
||||
return t;
|
||||
}
|
||||
} : adjust;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected CustomInstantDeserializer(CustomInstantDeserializer<T> base, DateTimeFormatter f) {
|
||||
super((Class<T>) base.handledType(), f);
|
||||
parsedToValue = base.parsedToValue;
|
||||
fromMilliseconds = base.fromMilliseconds;
|
||||
fromNanoseconds = base.fromNanoseconds;
|
||||
adjust = base.adjust;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonDeserializer<T> withDateFormat(DateTimeFormatter dtf) {
|
||||
if (dtf == _formatter) {
|
||||
return this;
|
||||
}
|
||||
return new CustomInstantDeserializer<T>(this, dtf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T deserialize(JsonParser parser, DeserializationContext context) throws IOException {
|
||||
//NOTE: Timestamps contain no timezone info, and are always in configured TZ. Only
|
||||
//string values have to be adjusted to the configured TZ.
|
||||
switch (parser.getCurrentTokenId()) {
|
||||
case JsonTokenId.ID_NUMBER_FLOAT: {
|
||||
BigDecimal value = parser.getDecimalValue();
|
||||
long seconds = value.longValue();
|
||||
int nanoseconds = DecimalUtils.extractNanosecondDecimal(value, seconds);
|
||||
return fromNanoseconds.apply(new FromDecimalArguments(
|
||||
seconds, nanoseconds, getZone(context)));
|
||||
}
|
||||
|
||||
case JsonTokenId.ID_NUMBER_INT: {
|
||||
long timestamp = parser.getLongValue();
|
||||
if (context.isEnabled(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS)) {
|
||||
return this.fromNanoseconds.apply(new FromDecimalArguments(
|
||||
timestamp, 0, this.getZone(context)
|
||||
));
|
||||
}
|
||||
return this.fromMilliseconds.apply(new FromIntegerArguments(
|
||||
timestamp, this.getZone(context)
|
||||
));
|
||||
}
|
||||
|
||||
case JsonTokenId.ID_STRING: {
|
||||
String string = parser.getText().trim();
|
||||
if (string.length() == 0) {
|
||||
return null;
|
||||
}
|
||||
if (string.endsWith("+0000")) {
|
||||
string = string.substring(0, string.length() - 5) + "Z";
|
||||
}
|
||||
T value;
|
||||
try {
|
||||
TemporalAccessor acc = _formatter.parse(string);
|
||||
value = parsedToValue.apply(acc);
|
||||
if (context.isEnabled(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)) {
|
||||
return adjust.apply(value, this.getZone(context));
|
||||
}
|
||||
} catch (DateTimeException e) {
|
||||
throw _peelDTE(e);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
throw context.mappingException("Expected type float, integer, or string.");
|
||||
}
|
||||
|
||||
private ZoneId getZone(DeserializationContext context) {
|
||||
// Instants are always in UTC, so don't waste compute cycles
|
||||
return (_valueClass == Instant.class) ? null : DateTimeUtils.timeZoneToZoneId(context.getTimeZone());
|
||||
}
|
||||
|
||||
private static class FromIntegerArguments {
|
||||
public final long value;
|
||||
public final ZoneId zoneId;
|
||||
|
||||
private FromIntegerArguments(long value, ZoneId zoneId) {
|
||||
this.value = value;
|
||||
this.zoneId = zoneId;
|
||||
}
|
||||
}
|
||||
|
||||
private static class FromDecimalArguments {
|
||||
public final long integer;
|
||||
public final int fraction;
|
||||
public final ZoneId zoneId;
|
||||
|
||||
private FromDecimalArguments(long integer, int fraction, ZoneId zoneId) {
|
||||
this.integer = integer;
|
||||
this.fraction = fraction;
|
||||
this.zoneId = zoneId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,8 +22,8 @@ import io.swagger.client.Pair;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import io.swagger.client.model.Client;
|
||||
import org.threeten.bp.LocalDate;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
import io.swagger.client.model.OuterComposite;
|
||||
|
||||
|
||||
@@ -261,7 +261,7 @@ public class FakeApi {
|
||||
* @param paramCallback None (optional)
|
||||
* @throws ApiException if fails to make API call
|
||||
*/
|
||||
public void testEndpointParameters(BigDecimal number, Double _double, String patternWithoutDelimiter, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, String string, byte[] binary, LocalDate date, OffsetDateTime dateTime, String password, String paramCallback) throws ApiException {
|
||||
public void testEndpointParameters(BigDecimal number, Double _double, String patternWithoutDelimiter, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, String string, byte[] binary, LocalDate date, DateTime dateTime, String password, String paramCallback) throws ApiException {
|
||||
Object localVarPostBody = null;
|
||||
|
||||
// verify the required parameter 'number' is set
|
||||
|
||||
@@ -21,8 +21,8 @@ import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.UUID;
|
||||
import org.threeten.bp.LocalDate;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
|
||||
/**
|
||||
* FormatTest
|
||||
@@ -60,7 +60,7 @@ public class FormatTest {
|
||||
private LocalDate date = null;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
private OffsetDateTime dateTime = null;
|
||||
private DateTime dateTime = null;
|
||||
|
||||
@JsonProperty("uuid")
|
||||
private UUID uuid = null;
|
||||
@@ -258,7 +258,7 @@ public class FormatTest {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public FormatTest dateTime(OffsetDateTime dateTime) {
|
||||
public FormatTest dateTime(DateTime dateTime) {
|
||||
this.dateTime = dateTime;
|
||||
return this;
|
||||
}
|
||||
@@ -268,11 +268,11 @@ public class FormatTest {
|
||||
* @return dateTime
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public OffsetDateTime getDateTime() {
|
||||
public DateTime getDateTime() {
|
||||
return dateTime;
|
||||
}
|
||||
|
||||
public void setDateTime(OffsetDateTime dateTime) {
|
||||
public void setDateTime(DateTime dateTime) {
|
||||
this.dateTime = dateTime;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/**
|
||||
* MixedPropertiesAndAdditionalPropertiesClass
|
||||
@@ -35,7 +35,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
|
||||
private UUID uuid = null;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
private OffsetDateTime dateTime = null;
|
||||
private DateTime dateTime = null;
|
||||
|
||||
@JsonProperty("map")
|
||||
private Map<String, Animal> map = null;
|
||||
@@ -58,7 +58,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public MixedPropertiesAndAdditionalPropertiesClass dateTime(OffsetDateTime dateTime) {
|
||||
public MixedPropertiesAndAdditionalPropertiesClass dateTime(DateTime dateTime) {
|
||||
this.dateTime = dateTime;
|
||||
return this;
|
||||
}
|
||||
@@ -68,11 +68,11 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
|
||||
* @return dateTime
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public OffsetDateTime getDateTime() {
|
||||
public DateTime getDateTime() {
|
||||
return dateTime;
|
||||
}
|
||||
|
||||
public void setDateTime(OffsetDateTime dateTime) {
|
||||
public void setDateTime(DateTime dateTime) {
|
||||
this.dateTime = dateTime;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/**
|
||||
* Order
|
||||
@@ -36,7 +36,7 @@ public class Order {
|
||||
private Integer quantity = null;
|
||||
|
||||
@JsonProperty("shipDate")
|
||||
private OffsetDateTime shipDate = null;
|
||||
private DateTime shipDate = null;
|
||||
|
||||
/**
|
||||
* Order Status
|
||||
@@ -135,7 +135,7 @@ public class Order {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public Order shipDate(OffsetDateTime shipDate) {
|
||||
public Order shipDate(DateTime shipDate) {
|
||||
this.shipDate = shipDate;
|
||||
return this;
|
||||
}
|
||||
@@ -145,11 +145,11 @@ public class Order {
|
||||
* @return shipDate
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public OffsetDateTime getShipDate() {
|
||||
public DateTime getShipDate() {
|
||||
return shipDate;
|
||||
}
|
||||
|
||||
public void setShipDate(OffsetDateTime shipDate) {
|
||||
public void setShipDate(DateTime shipDate) {
|
||||
this.shipDate = shipDate;
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
2.3.0-SNAPSHOT
|
||||
2.2.3-SNAPSHOT
|
||||
@@ -96,6 +96,7 @@ ext {
|
||||
swagger_annotations_version = "1.5.15"
|
||||
jackson_version = "2.8.9"
|
||||
jersey_version = "2.25.1"
|
||||
jodatime_version = "2.9.9"
|
||||
commons_io_version=2.5
|
||||
commons_lang3_version=3.6
|
||||
junit_version = "4.12"
|
||||
@@ -109,9 +110,10 @@ dependencies {
|
||||
compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
|
||||
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
|
||||
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
|
||||
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:$jackson_version"
|
||||
compile "joda-time:joda-time:$jodatime_version"
|
||||
compile "com.brsanthu:migbase64:2.2"
|
||||
compile "commons-io:commons-io:$commons_io_version"
|
||||
compile "org.apache.commons:commons-lang3:$commons_lang3_version"
|
||||
compile "com.github.joschi.jackson:jackson-datatype-threetenbp:$jackson_version",
|
||||
compile "com.brsanthu:migbase64:2.2"
|
||||
testCompile "junit:junit:$junit_version"
|
||||
}
|
||||
|
||||
@@ -13,10 +13,11 @@ lazy val root = (project in file(".")).
|
||||
"org.glassfish.jersey.core" % "jersey-client" % "2.25.1",
|
||||
"org.glassfish.jersey.media" % "jersey-media-multipart" % "2.25.1",
|
||||
"org.glassfish.jersey.media" % "jersey-media-json-jackson" % "2.25.1",
|
||||
"com.fasterxml.jackson.core" % "jackson-core" % "2.6.4" % "compile",
|
||||
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.6.4" % "compile",
|
||||
"com.fasterxml.jackson.core" % "jackson-databind" % "2.6.4" % "compile",
|
||||
"com.github.joschi.jackson" % "jackson-datatype-threetenbp" % "2.6.4" % "compile",
|
||||
"com.fasterxml.jackson.core" % "jackson-core" % "2.8.9",
|
||||
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.8.9",
|
||||
"com.fasterxml.jackson.core" % "jackson-databind" % "2.8.9",
|
||||
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % "2.8.9",
|
||||
"joda-time" % "joda-time" % "2.9.9",
|
||||
"com.brsanthu" % "migbase64" % "2.2",
|
||||
"org.apache.commons" % "commons-lang3" % "3.6",
|
||||
"commons-io" % "commons-io" % "2.5",
|
||||
|
||||
@@ -275,7 +275,7 @@ Float _float = 3.4F; // Float | None
|
||||
String string = "string_example"; // String | None
|
||||
byte[] binary = B; // byte[] | None
|
||||
LocalDate date = new LocalDate(); // LocalDate | None
|
||||
OffsetDateTime dateTime = new OffsetDateTime(); // OffsetDateTime | None
|
||||
DateTime dateTime = new DateTime(); // DateTime | None
|
||||
String password = "password_example"; // String | None
|
||||
String paramCallback = "paramCallback_example"; // String | None
|
||||
try {
|
||||
@@ -301,7 +301,7 @@ Name | Type | Description | Notes
|
||||
**string** | **String**| None | [optional]
|
||||
**binary** | **byte[]**| None | [optional]
|
||||
**date** | **LocalDate**| None | [optional]
|
||||
**dateTime** | **OffsetDateTime**| None | [optional]
|
||||
**dateTime** | **DateTime**| None | [optional]
|
||||
**password** | **String**| None | [optional]
|
||||
**paramCallback** | **String**| None | [optional]
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ Name | Type | Description | Notes
|
||||
**_byte** | **byte[]** | |
|
||||
**binary** | **byte[]** | | [optional]
|
||||
**date** | [**LocalDate**](LocalDate.md) | |
|
||||
**dateTime** | [**OffsetDateTime**](OffsetDateTime.md) | | [optional]
|
||||
**dateTime** | [**DateTime**](DateTime.md) | | [optional]
|
||||
**uuid** | [**UUID**](UUID.md) | | [optional]
|
||||
**password** | **String** | |
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**uuid** | [**UUID**](UUID.md) | | [optional]
|
||||
**dateTime** | [**OffsetDateTime**](OffsetDateTime.md) | | [optional]
|
||||
**dateTime** | [**DateTime**](DateTime.md) | | [optional]
|
||||
**map** | [**Map<String, Animal>**](Animal.md) | | [optional]
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ Name | Type | Description | Notes
|
||||
**id** | **Long** | | [optional]
|
||||
**petId** | **Long** | | [optional]
|
||||
**quantity** | **Integer** | | [optional]
|
||||
**shipDate** | [**OffsetDateTime**](OffsetDateTime.md) | | [optional]
|
||||
**shipDate** | [**DateTime**](DateTime.md) | | [optional]
|
||||
**status** | [**StatusEnum**](#StatusEnum) | Order Status | [optional]
|
||||
**complete** | **Boolean** | | [optional]
|
||||
|
||||
|
||||
@@ -217,10 +217,15 @@
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.joschi.jackson</groupId>
|
||||
<artifactId>jackson-datatype-threetenbp</artifactId>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-joda</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>${jodatime-version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Base64 encoding that works in both JVM and Android -->
|
||||
<dependency>
|
||||
@@ -228,6 +233,7 @@
|
||||
<artifactId>migbase64</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
@@ -251,9 +257,10 @@
|
||||
<properties>
|
||||
<swagger-core-version>1.5.15</swagger-core-version>
|
||||
<jersey-version>2.25.1</jersey-version>
|
||||
<jackson-version>2.8.9</jackson-version>
|
||||
<jodatime-version>2.9.9</jodatime-version>
|
||||
<commons_io_version>2.5</commons_io_version>
|
||||
<commons_lang3_version>3.6</commons_lang3_version>
|
||||
<jackson-version>2.6.4</jackson-version>
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
<junit-version>4.12</junit-version>
|
||||
</properties>
|
||||
|
||||
@@ -1,232 +0,0 @@
|
||||
package io.swagger.client;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.DateTimeUtils;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.DecimalUtils;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.deser.ThreeTenDateTimeDeserializerBase;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.function.BiFunction;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.function.Function;
|
||||
import org.threeten.bp.DateTimeException;
|
||||
import org.threeten.bp.Instant;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.threeten.bp.ZoneId;
|
||||
import org.threeten.bp.ZonedDateTime;
|
||||
import org.threeten.bp.format.DateTimeFormatter;
|
||||
import org.threeten.bp.temporal.Temporal;
|
||||
import org.threeten.bp.temporal.TemporalAccessor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* Deserializer for ThreeTen temporal {@link Instant}s, {@link OffsetDateTime}, and {@link ZonedDateTime}s.
|
||||
* Adapted from the jackson threetenbp InstantDeserializer to add support for deserializing rfc822 format.
|
||||
*
|
||||
* @author Nick Williams
|
||||
*/
|
||||
public class CustomInstantDeserializer<T extends Temporal>
|
||||
extends ThreeTenDateTimeDeserializerBase<T> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final CustomInstantDeserializer<Instant> INSTANT = new CustomInstantDeserializer<Instant>(
|
||||
Instant.class, DateTimeFormatter.ISO_INSTANT,
|
||||
new Function<TemporalAccessor, Instant>() {
|
||||
@Override
|
||||
public Instant apply(TemporalAccessor temporalAccessor) {
|
||||
return Instant.from(temporalAccessor);
|
||||
}
|
||||
},
|
||||
new Function<FromIntegerArguments, Instant>() {
|
||||
@Override
|
||||
public Instant apply(FromIntegerArguments a) {
|
||||
return Instant.ofEpochMilli(a.value);
|
||||
}
|
||||
},
|
||||
new Function<FromDecimalArguments, Instant>() {
|
||||
@Override
|
||||
public Instant apply(FromDecimalArguments a) {
|
||||
return Instant.ofEpochSecond(a.integer, a.fraction);
|
||||
}
|
||||
},
|
||||
null
|
||||
);
|
||||
|
||||
public static final CustomInstantDeserializer<OffsetDateTime> OFFSET_DATE_TIME = new CustomInstantDeserializer<OffsetDateTime>(
|
||||
OffsetDateTime.class, DateTimeFormatter.ISO_OFFSET_DATE_TIME,
|
||||
new Function<TemporalAccessor, OffsetDateTime>() {
|
||||
@Override
|
||||
public OffsetDateTime apply(TemporalAccessor temporalAccessor) {
|
||||
return OffsetDateTime.from(temporalAccessor);
|
||||
}
|
||||
},
|
||||
new Function<FromIntegerArguments, OffsetDateTime>() {
|
||||
@Override
|
||||
public OffsetDateTime apply(FromIntegerArguments a) {
|
||||
return OffsetDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId);
|
||||
}
|
||||
},
|
||||
new Function<FromDecimalArguments, OffsetDateTime>() {
|
||||
@Override
|
||||
public OffsetDateTime apply(FromDecimalArguments a) {
|
||||
return OffsetDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId);
|
||||
}
|
||||
},
|
||||
new BiFunction<OffsetDateTime, ZoneId, OffsetDateTime>() {
|
||||
@Override
|
||||
public OffsetDateTime apply(OffsetDateTime d, ZoneId z) {
|
||||
return d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime()));
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
public static final CustomInstantDeserializer<ZonedDateTime> ZONED_DATE_TIME = new CustomInstantDeserializer<ZonedDateTime>(
|
||||
ZonedDateTime.class, DateTimeFormatter.ISO_ZONED_DATE_TIME,
|
||||
new Function<TemporalAccessor, ZonedDateTime>() {
|
||||
@Override
|
||||
public ZonedDateTime apply(TemporalAccessor temporalAccessor) {
|
||||
return ZonedDateTime.from(temporalAccessor);
|
||||
}
|
||||
},
|
||||
new Function<FromIntegerArguments, ZonedDateTime>() {
|
||||
@Override
|
||||
public ZonedDateTime apply(FromIntegerArguments a) {
|
||||
return ZonedDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId);
|
||||
}
|
||||
},
|
||||
new Function<FromDecimalArguments, ZonedDateTime>() {
|
||||
@Override
|
||||
public ZonedDateTime apply(FromDecimalArguments a) {
|
||||
return ZonedDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId);
|
||||
}
|
||||
},
|
||||
new BiFunction<ZonedDateTime, ZoneId, ZonedDateTime>() {
|
||||
@Override
|
||||
public ZonedDateTime apply(ZonedDateTime zonedDateTime, ZoneId zoneId) {
|
||||
return zonedDateTime.withZoneSameInstant(zoneId);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
protected final Function<FromIntegerArguments, T> fromMilliseconds;
|
||||
|
||||
protected final Function<FromDecimalArguments, T> fromNanoseconds;
|
||||
|
||||
protected final Function<TemporalAccessor, T> parsedToValue;
|
||||
|
||||
protected final BiFunction<T, ZoneId, T> adjust;
|
||||
|
||||
protected CustomInstantDeserializer(Class<T> supportedType,
|
||||
DateTimeFormatter parser,
|
||||
Function<TemporalAccessor, T> parsedToValue,
|
||||
Function<FromIntegerArguments, T> fromMilliseconds,
|
||||
Function<FromDecimalArguments, T> fromNanoseconds,
|
||||
BiFunction<T, ZoneId, T> adjust) {
|
||||
super(supportedType, parser);
|
||||
this.parsedToValue = parsedToValue;
|
||||
this.fromMilliseconds = fromMilliseconds;
|
||||
this.fromNanoseconds = fromNanoseconds;
|
||||
this.adjust = adjust == null ? new BiFunction<T, ZoneId, T>() {
|
||||
@Override
|
||||
public T apply(T t, ZoneId zoneId) {
|
||||
return t;
|
||||
}
|
||||
} : adjust;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected CustomInstantDeserializer(CustomInstantDeserializer<T> base, DateTimeFormatter f) {
|
||||
super((Class<T>) base.handledType(), f);
|
||||
parsedToValue = base.parsedToValue;
|
||||
fromMilliseconds = base.fromMilliseconds;
|
||||
fromNanoseconds = base.fromNanoseconds;
|
||||
adjust = base.adjust;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonDeserializer<T> withDateFormat(DateTimeFormatter dtf) {
|
||||
if (dtf == _formatter) {
|
||||
return this;
|
||||
}
|
||||
return new CustomInstantDeserializer<T>(this, dtf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T deserialize(JsonParser parser, DeserializationContext context) throws IOException {
|
||||
//NOTE: Timestamps contain no timezone info, and are always in configured TZ. Only
|
||||
//string values have to be adjusted to the configured TZ.
|
||||
switch (parser.getCurrentTokenId()) {
|
||||
case JsonTokenId.ID_NUMBER_FLOAT: {
|
||||
BigDecimal value = parser.getDecimalValue();
|
||||
long seconds = value.longValue();
|
||||
int nanoseconds = DecimalUtils.extractNanosecondDecimal(value, seconds);
|
||||
return fromNanoseconds.apply(new FromDecimalArguments(
|
||||
seconds, nanoseconds, getZone(context)));
|
||||
}
|
||||
|
||||
case JsonTokenId.ID_NUMBER_INT: {
|
||||
long timestamp = parser.getLongValue();
|
||||
if (context.isEnabled(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS)) {
|
||||
return this.fromNanoseconds.apply(new FromDecimalArguments(
|
||||
timestamp, 0, this.getZone(context)
|
||||
));
|
||||
}
|
||||
return this.fromMilliseconds.apply(new FromIntegerArguments(
|
||||
timestamp, this.getZone(context)
|
||||
));
|
||||
}
|
||||
|
||||
case JsonTokenId.ID_STRING: {
|
||||
String string = parser.getText().trim();
|
||||
if (string.length() == 0) {
|
||||
return null;
|
||||
}
|
||||
if (string.endsWith("+0000")) {
|
||||
string = string.substring(0, string.length() - 5) + "Z";
|
||||
}
|
||||
T value;
|
||||
try {
|
||||
TemporalAccessor acc = _formatter.parse(string);
|
||||
value = parsedToValue.apply(acc);
|
||||
if (context.isEnabled(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)) {
|
||||
return adjust.apply(value, this.getZone(context));
|
||||
}
|
||||
} catch (DateTimeException e) {
|
||||
throw _peelDTE(e);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
throw context.mappingException("Expected type float, integer, or string.");
|
||||
}
|
||||
|
||||
private ZoneId getZone(DeserializationContext context) {
|
||||
// Instants are always in UTC, so don't waste compute cycles
|
||||
return (_valueClass == Instant.class) ? null : DateTimeUtils.timeZoneToZoneId(context.getTimeZone());
|
||||
}
|
||||
|
||||
private static class FromIntegerArguments {
|
||||
public final long value;
|
||||
public final ZoneId zoneId;
|
||||
|
||||
private FromIntegerArguments(long value, ZoneId zoneId) {
|
||||
this.value = value;
|
||||
this.zoneId = zoneId;
|
||||
}
|
||||
}
|
||||
|
||||
private static class FromDecimalArguments {
|
||||
public final long integer;
|
||||
public final int fraction;
|
||||
public final ZoneId zoneId;
|
||||
|
||||
private FromDecimalArguments(long integer, int fraction, ZoneId zoneId) {
|
||||
this.integer = integer;
|
||||
this.fraction = fraction;
|
||||
this.zoneId = zoneId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
package io.swagger.client;
|
||||
|
||||
import org.threeten.bp.*;
|
||||
import com.fasterxml.jackson.annotation.*;
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.ThreeTenModule;
|
||||
import com.fasterxml.jackson.datatype.joda.*;
|
||||
|
||||
import java.text.DateFormat;
|
||||
|
||||
@@ -22,11 +21,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
mapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
|
||||
mapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
|
||||
mapper.setDateFormat(new RFC3339DateFormat());
|
||||
ThreeTenModule module = new ThreeTenModule();
|
||||
module.addDeserializer(Instant.class, CustomInstantDeserializer.INSTANT);
|
||||
module.addDeserializer(OffsetDateTime.class, CustomInstantDeserializer.OFFSET_DATE_TIME);
|
||||
module.addDeserializer(ZonedDateTime.class, CustomInstantDeserializer.ZONED_DATE_TIME);
|
||||
mapper.registerModule(module);
|
||||
mapper.registerModule(new JodaModule());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,8 +9,8 @@ import javax.ws.rs.core.GenericType;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import io.swagger.client.model.Client;
|
||||
import org.threeten.bp.LocalDate;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
import io.swagger.client.model.OuterComposite;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -242,7 +242,7 @@ public class FakeApi {
|
||||
* @param paramCallback None (optional)
|
||||
* @throws ApiException if fails to make API call
|
||||
*/
|
||||
public void testEndpointParameters(BigDecimal number, Double _double, String patternWithoutDelimiter, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, String string, byte[] binary, LocalDate date, OffsetDateTime dateTime, String password, String paramCallback) throws ApiException {
|
||||
public void testEndpointParameters(BigDecimal number, Double _double, String patternWithoutDelimiter, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, String string, byte[] binary, LocalDate date, DateTime dateTime, String password, String paramCallback) throws ApiException {
|
||||
Object localVarPostBody = null;
|
||||
|
||||
// verify the required parameter 'number' is set
|
||||
|
||||
@@ -21,8 +21,8 @@ import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.UUID;
|
||||
import org.threeten.bp.LocalDate;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
|
||||
/**
|
||||
* FormatTest
|
||||
@@ -60,7 +60,7 @@ public class FormatTest {
|
||||
private LocalDate date = null;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
private OffsetDateTime dateTime = null;
|
||||
private DateTime dateTime = null;
|
||||
|
||||
@JsonProperty("uuid")
|
||||
private UUID uuid = null;
|
||||
@@ -258,7 +258,7 @@ public class FormatTest {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public FormatTest dateTime(OffsetDateTime dateTime) {
|
||||
public FormatTest dateTime(DateTime dateTime) {
|
||||
this.dateTime = dateTime;
|
||||
return this;
|
||||
}
|
||||
@@ -268,11 +268,11 @@ public class FormatTest {
|
||||
* @return dateTime
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public OffsetDateTime getDateTime() {
|
||||
public DateTime getDateTime() {
|
||||
return dateTime;
|
||||
}
|
||||
|
||||
public void setDateTime(OffsetDateTime dateTime) {
|
||||
public void setDateTime(DateTime dateTime) {
|
||||
this.dateTime = dateTime;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/**
|
||||
* MixedPropertiesAndAdditionalPropertiesClass
|
||||
@@ -35,7 +35,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
|
||||
private UUID uuid = null;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
private OffsetDateTime dateTime = null;
|
||||
private DateTime dateTime = null;
|
||||
|
||||
@JsonProperty("map")
|
||||
private Map<String, Animal> map = null;
|
||||
@@ -58,7 +58,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public MixedPropertiesAndAdditionalPropertiesClass dateTime(OffsetDateTime dateTime) {
|
||||
public MixedPropertiesAndAdditionalPropertiesClass dateTime(DateTime dateTime) {
|
||||
this.dateTime = dateTime;
|
||||
return this;
|
||||
}
|
||||
@@ -68,11 +68,11 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
|
||||
* @return dateTime
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public OffsetDateTime getDateTime() {
|
||||
public DateTime getDateTime() {
|
||||
return dateTime;
|
||||
}
|
||||
|
||||
public void setDateTime(OffsetDateTime dateTime) {
|
||||
public void setDateTime(DateTime dateTime) {
|
||||
this.dateTime = dateTime;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/**
|
||||
* Order
|
||||
@@ -36,7 +36,7 @@ public class Order {
|
||||
private Integer quantity = null;
|
||||
|
||||
@JsonProperty("shipDate")
|
||||
private OffsetDateTime shipDate = null;
|
||||
private DateTime shipDate = null;
|
||||
|
||||
/**
|
||||
* Order Status
|
||||
@@ -135,7 +135,7 @@ public class Order {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public Order shipDate(OffsetDateTime shipDate) {
|
||||
public Order shipDate(DateTime shipDate) {
|
||||
this.shipDate = shipDate;
|
||||
return this;
|
||||
}
|
||||
@@ -145,11 +145,11 @@ public class Order {
|
||||
* @return shipDate
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public OffsetDateTime getShipDate() {
|
||||
public DateTime getShipDate() {
|
||||
return shipDate;
|
||||
}
|
||||
|
||||
public void setShipDate(OffsetDateTime shipDate) {
|
||||
public void setShipDate(DateTime shipDate) {
|
||||
this.shipDate = shipDate;
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
2.3.0-SNAPSHOT
|
||||
2.2.3-SNAPSHOT
|
||||
@@ -107,7 +107,6 @@ dependencies {
|
||||
compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
|
||||
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
|
||||
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
|
||||
compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson_version",
|
||||
compile "com.brsanthu:migbase64:2.2"
|
||||
compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson_version"
|
||||
testCompile "junit:junit:$junit_version"
|
||||
}
|
||||
|
||||
@@ -13,10 +13,10 @@ lazy val root = (project in file(".")).
|
||||
"org.glassfish.jersey.core" % "jersey-client" % "2.25.1",
|
||||
"org.glassfish.jersey.media" % "jersey-media-multipart" % "2.25.1",
|
||||
"org.glassfish.jersey.media" % "jersey-media-json-jackson" % "2.25.1",
|
||||
"com.fasterxml.jackson.core" % "jackson-core" % "2.8.9" % "compile",
|
||||
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.8.9" % "compile",
|
||||
"com.fasterxml.jackson.core" % "jackson-databind" % "2.8.9" % "compile",
|
||||
"com.fasterxml.jackson.datatype" % "jackson-datatype-jsr310" % "2.8.9" % "compile",
|
||||
"com.fasterxml.jackson.core" % "jackson-core" % "2.8.9",
|
||||
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.8.9",
|
||||
"com.fasterxml.jackson.core" % "jackson-databind" % "2.8.9",
|
||||
"com.fasterxml.jackson.datatype" % "jackson-datatype-jsr310" % "2.8.9",
|
||||
"com.brsanthu" % "migbase64" % "2.2",
|
||||
"junit" % "junit" % "4.12" % "test",
|
||||
"com.novocode" % "junit-interface" % "0.10" % "test"
|
||||
|
||||
@@ -222,12 +222,6 @@
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Base64 encoding that works in both JVM and Android -->
|
||||
<dependency>
|
||||
<groupId>com.brsanthu</groupId>
|
||||
<artifactId>migbase64</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
@@ -240,7 +234,7 @@
|
||||
<properties>
|
||||
<swagger-core-version>1.5.15</swagger-core-version>
|
||||
<jersey-version>2.25.1</jersey-version>
|
||||
<jackson-version>2.7.5</jackson-version>
|
||||
<jackson-version>2.8.9</jackson-version>
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
<junit-version>4.12</junit-version>
|
||||
</properties>
|
||||
|
||||
@@ -2,7 +2,7 @@ package io.swagger.client;
|
||||
|
||||
import com.fasterxml.jackson.annotation.*;
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.*;
|
||||
|
||||
import java.text.DateFormat;
|
||||
|
||||
|
||||
@@ -15,12 +15,12 @@ package io.swagger.client.auth;
|
||||
|
||||
import io.swagger.client.Pair;
|
||||
|
||||
import com.migcomponents.migbase64.Base64;
|
||||
import java.util.Base64;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
|
||||
public class HttpBasicAuth implements Authentication {
|
||||
@@ -49,10 +49,6 @@ public class HttpBasicAuth implements Authentication {
|
||||
return;
|
||||
}
|
||||
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
|
||||
try {
|
||||
headerParams.put("Authorization", "Basic " + Base64.encodeToString(str.getBytes("UTF-8"), false));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
headerParams.put("Authorization", "Basic " + Base64.getEncoder().encodeToString(str.getBytes(StandardCharsets.UTF_8)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
2.3.0-SNAPSHOT
|
||||
2.2.3-SNAPSHOT
|
||||
@@ -96,6 +96,7 @@ ext {
|
||||
swagger_annotations_version = "1.5.15"
|
||||
jackson_version = "2.8.9"
|
||||
jersey_version = "2.25.1"
|
||||
jodatime_version = "2.9.9"
|
||||
junit_version = "4.12"
|
||||
}
|
||||
|
||||
@@ -107,7 +108,8 @@ dependencies {
|
||||
compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
|
||||
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
|
||||
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
|
||||
compile "com.github.joschi.jackson:jackson-datatype-threetenbp:$jackson_version",
|
||||
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:$jackson_version"
|
||||
compile "joda-time:joda-time:$jodatime_version"
|
||||
compile "com.brsanthu:migbase64:2.2"
|
||||
testCompile "junit:junit:$junit_version"
|
||||
}
|
||||
|
||||
@@ -13,10 +13,11 @@ lazy val root = (project in file(".")).
|
||||
"org.glassfish.jersey.core" % "jersey-client" % "2.25.1",
|
||||
"org.glassfish.jersey.media" % "jersey-media-multipart" % "2.25.1",
|
||||
"org.glassfish.jersey.media" % "jersey-media-json-jackson" % "2.25.1",
|
||||
"com.fasterxml.jackson.core" % "jackson-core" % "2.6.4" % "compile",
|
||||
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.6.4" % "compile",
|
||||
"com.fasterxml.jackson.core" % "jackson-databind" % "2.6.4" % "compile",
|
||||
"com.github.joschi.jackson" % "jackson-datatype-threetenbp" % "2.6.4" % "compile",
|
||||
"com.fasterxml.jackson.core" % "jackson-core" % "2.8.9",
|
||||
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.8.9",
|
||||
"com.fasterxml.jackson.core" % "jackson-databind" % "2.8.9",
|
||||
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % "2.8.9",
|
||||
"joda-time" % "joda-time" % "2.9.9",
|
||||
"com.brsanthu" % "migbase64" % "2.2",
|
||||
"junit" % "junit" % "4.12" % "test",
|
||||
"com.novocode" % "junit-interface" % "0.10" % "test"
|
||||
|
||||
@@ -275,7 +275,7 @@ Float _float = 3.4F; // Float | None
|
||||
String string = "string_example"; // String | None
|
||||
byte[] binary = B; // byte[] | None
|
||||
LocalDate date = new LocalDate(); // LocalDate | None
|
||||
OffsetDateTime dateTime = new OffsetDateTime(); // OffsetDateTime | None
|
||||
DateTime dateTime = new DateTime(); // DateTime | None
|
||||
String password = "password_example"; // String | None
|
||||
String paramCallback = "paramCallback_example"; // String | None
|
||||
try {
|
||||
@@ -301,7 +301,7 @@ Name | Type | Description | Notes
|
||||
**string** | **String**| None | [optional]
|
||||
**binary** | **byte[]**| None | [optional]
|
||||
**date** | **LocalDate**| None | [optional]
|
||||
**dateTime** | **OffsetDateTime**| None | [optional]
|
||||
**dateTime** | **DateTime**| None | [optional]
|
||||
**password** | **String**| None | [optional]
|
||||
**paramCallback** | **String**| None | [optional]
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ Name | Type | Description | Notes
|
||||
**_byte** | **byte[]** | |
|
||||
**binary** | **byte[]** | | [optional]
|
||||
**date** | [**LocalDate**](LocalDate.md) | |
|
||||
**dateTime** | [**OffsetDateTime**](OffsetDateTime.md) | | [optional]
|
||||
**dateTime** | [**DateTime**](DateTime.md) | | [optional]
|
||||
**uuid** | [**UUID**](UUID.md) | | [optional]
|
||||
**password** | **String** | |
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**uuid** | [**UUID**](UUID.md) | | [optional]
|
||||
**dateTime** | [**OffsetDateTime**](OffsetDateTime.md) | | [optional]
|
||||
**dateTime** | [**DateTime**](DateTime.md) | | [optional]
|
||||
**map** | [**Map<String, Animal>**](Animal.md) | | [optional]
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ Name | Type | Description | Notes
|
||||
**id** | **Long** | | [optional]
|
||||
**petId** | **Long** | | [optional]
|
||||
**quantity** | **Integer** | | [optional]
|
||||
**shipDate** | [**OffsetDateTime**](OffsetDateTime.md) | | [optional]
|
||||
**shipDate** | [**DateTime**](DateTime.md) | | [optional]
|
||||
**status** | [**StatusEnum**](#StatusEnum) | Order Status | [optional]
|
||||
**complete** | **Boolean** | | [optional]
|
||||
|
||||
|
||||
@@ -217,10 +217,15 @@
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.joschi.jackson</groupId>
|
||||
<artifactId>jackson-datatype-threetenbp</artifactId>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-joda</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>${jodatime-version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Base64 encoding that works in both JVM and Android -->
|
||||
<dependency>
|
||||
@@ -229,6 +234,7 @@
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
@@ -240,7 +246,8 @@
|
||||
<properties>
|
||||
<swagger-core-version>1.5.15</swagger-core-version>
|
||||
<jersey-version>2.25.1</jersey-version>
|
||||
<jackson-version>2.6.4</jackson-version>
|
||||
<jackson-version>2.8.9</jackson-version>
|
||||
<jodatime-version>2.9.9</jodatime-version>
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
<junit-version>4.12</junit-version>
|
||||
</properties>
|
||||
|
||||
@@ -1,232 +0,0 @@
|
||||
package io.swagger.client;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.DateTimeUtils;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.DecimalUtils;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.deser.ThreeTenDateTimeDeserializerBase;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.function.BiFunction;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.function.Function;
|
||||
import org.threeten.bp.DateTimeException;
|
||||
import org.threeten.bp.Instant;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.threeten.bp.ZoneId;
|
||||
import org.threeten.bp.ZonedDateTime;
|
||||
import org.threeten.bp.format.DateTimeFormatter;
|
||||
import org.threeten.bp.temporal.Temporal;
|
||||
import org.threeten.bp.temporal.TemporalAccessor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* Deserializer for ThreeTen temporal {@link Instant}s, {@link OffsetDateTime}, and {@link ZonedDateTime}s.
|
||||
* Adapted from the jackson threetenbp InstantDeserializer to add support for deserializing rfc822 format.
|
||||
*
|
||||
* @author Nick Williams
|
||||
*/
|
||||
public class CustomInstantDeserializer<T extends Temporal>
|
||||
extends ThreeTenDateTimeDeserializerBase<T> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final CustomInstantDeserializer<Instant> INSTANT = new CustomInstantDeserializer<Instant>(
|
||||
Instant.class, DateTimeFormatter.ISO_INSTANT,
|
||||
new Function<TemporalAccessor, Instant>() {
|
||||
@Override
|
||||
public Instant apply(TemporalAccessor temporalAccessor) {
|
||||
return Instant.from(temporalAccessor);
|
||||
}
|
||||
},
|
||||
new Function<FromIntegerArguments, Instant>() {
|
||||
@Override
|
||||
public Instant apply(FromIntegerArguments a) {
|
||||
return Instant.ofEpochMilli(a.value);
|
||||
}
|
||||
},
|
||||
new Function<FromDecimalArguments, Instant>() {
|
||||
@Override
|
||||
public Instant apply(FromDecimalArguments a) {
|
||||
return Instant.ofEpochSecond(a.integer, a.fraction);
|
||||
}
|
||||
},
|
||||
null
|
||||
);
|
||||
|
||||
public static final CustomInstantDeserializer<OffsetDateTime> OFFSET_DATE_TIME = new CustomInstantDeserializer<OffsetDateTime>(
|
||||
OffsetDateTime.class, DateTimeFormatter.ISO_OFFSET_DATE_TIME,
|
||||
new Function<TemporalAccessor, OffsetDateTime>() {
|
||||
@Override
|
||||
public OffsetDateTime apply(TemporalAccessor temporalAccessor) {
|
||||
return OffsetDateTime.from(temporalAccessor);
|
||||
}
|
||||
},
|
||||
new Function<FromIntegerArguments, OffsetDateTime>() {
|
||||
@Override
|
||||
public OffsetDateTime apply(FromIntegerArguments a) {
|
||||
return OffsetDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId);
|
||||
}
|
||||
},
|
||||
new Function<FromDecimalArguments, OffsetDateTime>() {
|
||||
@Override
|
||||
public OffsetDateTime apply(FromDecimalArguments a) {
|
||||
return OffsetDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId);
|
||||
}
|
||||
},
|
||||
new BiFunction<OffsetDateTime, ZoneId, OffsetDateTime>() {
|
||||
@Override
|
||||
public OffsetDateTime apply(OffsetDateTime d, ZoneId z) {
|
||||
return d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime()));
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
public static final CustomInstantDeserializer<ZonedDateTime> ZONED_DATE_TIME = new CustomInstantDeserializer<ZonedDateTime>(
|
||||
ZonedDateTime.class, DateTimeFormatter.ISO_ZONED_DATE_TIME,
|
||||
new Function<TemporalAccessor, ZonedDateTime>() {
|
||||
@Override
|
||||
public ZonedDateTime apply(TemporalAccessor temporalAccessor) {
|
||||
return ZonedDateTime.from(temporalAccessor);
|
||||
}
|
||||
},
|
||||
new Function<FromIntegerArguments, ZonedDateTime>() {
|
||||
@Override
|
||||
public ZonedDateTime apply(FromIntegerArguments a) {
|
||||
return ZonedDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId);
|
||||
}
|
||||
},
|
||||
new Function<FromDecimalArguments, ZonedDateTime>() {
|
||||
@Override
|
||||
public ZonedDateTime apply(FromDecimalArguments a) {
|
||||
return ZonedDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId);
|
||||
}
|
||||
},
|
||||
new BiFunction<ZonedDateTime, ZoneId, ZonedDateTime>() {
|
||||
@Override
|
||||
public ZonedDateTime apply(ZonedDateTime zonedDateTime, ZoneId zoneId) {
|
||||
return zonedDateTime.withZoneSameInstant(zoneId);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
protected final Function<FromIntegerArguments, T> fromMilliseconds;
|
||||
|
||||
protected final Function<FromDecimalArguments, T> fromNanoseconds;
|
||||
|
||||
protected final Function<TemporalAccessor, T> parsedToValue;
|
||||
|
||||
protected final BiFunction<T, ZoneId, T> adjust;
|
||||
|
||||
protected CustomInstantDeserializer(Class<T> supportedType,
|
||||
DateTimeFormatter parser,
|
||||
Function<TemporalAccessor, T> parsedToValue,
|
||||
Function<FromIntegerArguments, T> fromMilliseconds,
|
||||
Function<FromDecimalArguments, T> fromNanoseconds,
|
||||
BiFunction<T, ZoneId, T> adjust) {
|
||||
super(supportedType, parser);
|
||||
this.parsedToValue = parsedToValue;
|
||||
this.fromMilliseconds = fromMilliseconds;
|
||||
this.fromNanoseconds = fromNanoseconds;
|
||||
this.adjust = adjust == null ? new BiFunction<T, ZoneId, T>() {
|
||||
@Override
|
||||
public T apply(T t, ZoneId zoneId) {
|
||||
return t;
|
||||
}
|
||||
} : adjust;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected CustomInstantDeserializer(CustomInstantDeserializer<T> base, DateTimeFormatter f) {
|
||||
super((Class<T>) base.handledType(), f);
|
||||
parsedToValue = base.parsedToValue;
|
||||
fromMilliseconds = base.fromMilliseconds;
|
||||
fromNanoseconds = base.fromNanoseconds;
|
||||
adjust = base.adjust;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonDeserializer<T> withDateFormat(DateTimeFormatter dtf) {
|
||||
if (dtf == _formatter) {
|
||||
return this;
|
||||
}
|
||||
return new CustomInstantDeserializer<T>(this, dtf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T deserialize(JsonParser parser, DeserializationContext context) throws IOException {
|
||||
//NOTE: Timestamps contain no timezone info, and are always in configured TZ. Only
|
||||
//string values have to be adjusted to the configured TZ.
|
||||
switch (parser.getCurrentTokenId()) {
|
||||
case JsonTokenId.ID_NUMBER_FLOAT: {
|
||||
BigDecimal value = parser.getDecimalValue();
|
||||
long seconds = value.longValue();
|
||||
int nanoseconds = DecimalUtils.extractNanosecondDecimal(value, seconds);
|
||||
return fromNanoseconds.apply(new FromDecimalArguments(
|
||||
seconds, nanoseconds, getZone(context)));
|
||||
}
|
||||
|
||||
case JsonTokenId.ID_NUMBER_INT: {
|
||||
long timestamp = parser.getLongValue();
|
||||
if (context.isEnabled(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS)) {
|
||||
return this.fromNanoseconds.apply(new FromDecimalArguments(
|
||||
timestamp, 0, this.getZone(context)
|
||||
));
|
||||
}
|
||||
return this.fromMilliseconds.apply(new FromIntegerArguments(
|
||||
timestamp, this.getZone(context)
|
||||
));
|
||||
}
|
||||
|
||||
case JsonTokenId.ID_STRING: {
|
||||
String string = parser.getText().trim();
|
||||
if (string.length() == 0) {
|
||||
return null;
|
||||
}
|
||||
if (string.endsWith("+0000")) {
|
||||
string = string.substring(0, string.length() - 5) + "Z";
|
||||
}
|
||||
T value;
|
||||
try {
|
||||
TemporalAccessor acc = _formatter.parse(string);
|
||||
value = parsedToValue.apply(acc);
|
||||
if (context.isEnabled(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)) {
|
||||
return adjust.apply(value, this.getZone(context));
|
||||
}
|
||||
} catch (DateTimeException e) {
|
||||
throw _peelDTE(e);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
throw context.mappingException("Expected type float, integer, or string.");
|
||||
}
|
||||
|
||||
private ZoneId getZone(DeserializationContext context) {
|
||||
// Instants are always in UTC, so don't waste compute cycles
|
||||
return (_valueClass == Instant.class) ? null : DateTimeUtils.timeZoneToZoneId(context.getTimeZone());
|
||||
}
|
||||
|
||||
private static class FromIntegerArguments {
|
||||
public final long value;
|
||||
public final ZoneId zoneId;
|
||||
|
||||
private FromIntegerArguments(long value, ZoneId zoneId) {
|
||||
this.value = value;
|
||||
this.zoneId = zoneId;
|
||||
}
|
||||
}
|
||||
|
||||
private static class FromDecimalArguments {
|
||||
public final long integer;
|
||||
public final int fraction;
|
||||
public final ZoneId zoneId;
|
||||
|
||||
private FromDecimalArguments(long integer, int fraction, ZoneId zoneId) {
|
||||
this.integer = integer;
|
||||
this.fraction = fraction;
|
||||
this.zoneId = zoneId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
package io.swagger.client;
|
||||
|
||||
import org.threeten.bp.*;
|
||||
import com.fasterxml.jackson.annotation.*;
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import com.fasterxml.jackson.datatype.threetenbp.ThreeTenModule;
|
||||
import com.fasterxml.jackson.datatype.joda.*;
|
||||
|
||||
import java.text.DateFormat;
|
||||
|
||||
@@ -22,11 +21,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
mapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
|
||||
mapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
|
||||
mapper.setDateFormat(new RFC3339DateFormat());
|
||||
ThreeTenModule module = new ThreeTenModule();
|
||||
module.addDeserializer(Instant.class, CustomInstantDeserializer.INSTANT);
|
||||
module.addDeserializer(OffsetDateTime.class, CustomInstantDeserializer.OFFSET_DATE_TIME);
|
||||
module.addDeserializer(ZonedDateTime.class, CustomInstantDeserializer.ZONED_DATE_TIME);
|
||||
mapper.registerModule(module);
|
||||
mapper.registerModule(new JodaModule());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,8 +9,8 @@ import javax.ws.rs.core.GenericType;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import io.swagger.client.model.Client;
|
||||
import org.threeten.bp.LocalDate;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
import io.swagger.client.model.OuterComposite;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -242,7 +242,7 @@ public class FakeApi {
|
||||
* @param paramCallback None (optional)
|
||||
* @throws ApiException if fails to make API call
|
||||
*/
|
||||
public void testEndpointParameters(BigDecimal number, Double _double, String patternWithoutDelimiter, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, String string, byte[] binary, LocalDate date, OffsetDateTime dateTime, String password, String paramCallback) throws ApiException {
|
||||
public void testEndpointParameters(BigDecimal number, Double _double, String patternWithoutDelimiter, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, String string, byte[] binary, LocalDate date, DateTime dateTime, String password, String paramCallback) throws ApiException {
|
||||
Object localVarPostBody = null;
|
||||
|
||||
// verify the required parameter 'number' is set
|
||||
|
||||
@@ -21,8 +21,8 @@ import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.UUID;
|
||||
import org.threeten.bp.LocalDate;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
|
||||
/**
|
||||
* FormatTest
|
||||
@@ -60,7 +60,7 @@ public class FormatTest {
|
||||
private LocalDate date = null;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
private OffsetDateTime dateTime = null;
|
||||
private DateTime dateTime = null;
|
||||
|
||||
@JsonProperty("uuid")
|
||||
private UUID uuid = null;
|
||||
@@ -258,7 +258,7 @@ public class FormatTest {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public FormatTest dateTime(OffsetDateTime dateTime) {
|
||||
public FormatTest dateTime(DateTime dateTime) {
|
||||
this.dateTime = dateTime;
|
||||
return this;
|
||||
}
|
||||
@@ -268,11 +268,11 @@ public class FormatTest {
|
||||
* @return dateTime
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public OffsetDateTime getDateTime() {
|
||||
public DateTime getDateTime() {
|
||||
return dateTime;
|
||||
}
|
||||
|
||||
public void setDateTime(OffsetDateTime dateTime) {
|
||||
public void setDateTime(DateTime dateTime) {
|
||||
this.dateTime = dateTime;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/**
|
||||
* MixedPropertiesAndAdditionalPropertiesClass
|
||||
@@ -35,7 +35,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
|
||||
private UUID uuid = null;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
private OffsetDateTime dateTime = null;
|
||||
private DateTime dateTime = null;
|
||||
|
||||
@JsonProperty("map")
|
||||
private Map<String, Animal> map = null;
|
||||
@@ -58,7 +58,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public MixedPropertiesAndAdditionalPropertiesClass dateTime(OffsetDateTime dateTime) {
|
||||
public MixedPropertiesAndAdditionalPropertiesClass dateTime(DateTime dateTime) {
|
||||
this.dateTime = dateTime;
|
||||
return this;
|
||||
}
|
||||
@@ -68,11 +68,11 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
|
||||
* @return dateTime
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public OffsetDateTime getDateTime() {
|
||||
public DateTime getDateTime() {
|
||||
return dateTime;
|
||||
}
|
||||
|
||||
public void setDateTime(OffsetDateTime dateTime) {
|
||||
public void setDateTime(DateTime dateTime) {
|
||||
this.dateTime = dateTime;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/**
|
||||
* Order
|
||||
@@ -36,7 +36,7 @@ public class Order {
|
||||
private Integer quantity = null;
|
||||
|
||||
@JsonProperty("shipDate")
|
||||
private OffsetDateTime shipDate = null;
|
||||
private DateTime shipDate = null;
|
||||
|
||||
/**
|
||||
* Order Status
|
||||
@@ -135,7 +135,7 @@ public class Order {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public Order shipDate(OffsetDateTime shipDate) {
|
||||
public Order shipDate(DateTime shipDate) {
|
||||
this.shipDate = shipDate;
|
||||
return this;
|
||||
}
|
||||
@@ -145,11 +145,11 @@ public class Order {
|
||||
* @return shipDate
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public OffsetDateTime getShipDate() {
|
||||
public DateTime getShipDate() {
|
||||
return shipDate;
|
||||
}
|
||||
|
||||
public void setShipDate(OffsetDateTime shipDate) {
|
||||
public void setShipDate(DateTime shipDate) {
|
||||
this.shipDate = shipDate;
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
2.3.0-SNAPSHOT
|
||||
2.2.3-SNAPSHOT
|
||||
@@ -98,6 +98,6 @@ dependencies {
|
||||
compile 'com.squareup.okhttp:okhttp:2.7.5'
|
||||
compile 'com.squareup.okhttp:logging-interceptor:2.7.5'
|
||||
compile 'com.google.code.gson:gson:2.8.1'
|
||||
compile 'org.threeten:threetenbp:1.3.5'
|
||||
compile 'joda-time:joda-time:2.9.9'
|
||||
testCompile 'junit:junit:4.12'
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ lazy val root = (project in file(".")).
|
||||
"com.squareup.okhttp" % "okhttp" % "2.7.5",
|
||||
"com.squareup.okhttp" % "logging-interceptor" % "2.7.5",
|
||||
"com.google.code.gson" % "gson" % "2.8.1",
|
||||
"org.threeten" % "threetenbp" % "1.3.5" % "compile",
|
||||
"joda-time" % "joda-time" % "2.9.9" % "compile",
|
||||
"junit" % "junit" % "4.12" % "test",
|
||||
"com.novocode" % "junit-interface" % "0.10" % "test"
|
||||
)
|
||||
|
||||
@@ -275,7 +275,7 @@ Float _float = 3.4F; // Float | None
|
||||
String string = "string_example"; // String | None
|
||||
byte[] binary = B; // byte[] | None
|
||||
LocalDate date = new LocalDate(); // LocalDate | None
|
||||
OffsetDateTime dateTime = new OffsetDateTime(); // OffsetDateTime | None
|
||||
DateTime dateTime = new DateTime(); // DateTime | None
|
||||
String password = "password_example"; // String | None
|
||||
String paramCallback = "paramCallback_example"; // String | None
|
||||
try {
|
||||
@@ -301,7 +301,7 @@ Name | Type | Description | Notes
|
||||
**string** | **String**| None | [optional]
|
||||
**binary** | **byte[]**| None | [optional]
|
||||
**date** | **LocalDate**| None | [optional]
|
||||
**dateTime** | **OffsetDateTime**| None | [optional]
|
||||
**dateTime** | **DateTime**| None | [optional]
|
||||
**password** | **String**| None | [optional]
|
||||
**paramCallback** | **String**| None | [optional]
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ Name | Type | Description | Notes
|
||||
**_byte** | **byte[]** | |
|
||||
**binary** | **byte[]** | | [optional]
|
||||
**date** | [**LocalDate**](LocalDate.md) | |
|
||||
**dateTime** | [**OffsetDateTime**](OffsetDateTime.md) | | [optional]
|
||||
**dateTime** | [**DateTime**](DateTime.md) | | [optional]
|
||||
**uuid** | [**UUID**](UUID.md) | | [optional]
|
||||
**password** | **String** | |
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**uuid** | [**UUID**](UUID.md) | | [optional]
|
||||
**dateTime** | [**OffsetDateTime**](OffsetDateTime.md) | | [optional]
|
||||
**dateTime** | [**DateTime**](DateTime.md) | | [optional]
|
||||
**map** | [**Map<String, Animal>**](Animal.md) | | [optional]
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ Name | Type | Description | Notes
|
||||
**id** | **Long** | | [optional]
|
||||
**petId** | **Long** | | [optional]
|
||||
**quantity** | **Integer** | | [optional]
|
||||
**shipDate** | [**OffsetDateTime**](OffsetDateTime.md) | | [optional]
|
||||
**shipDate** | [**DateTime**](DateTime.md) | | [optional]
|
||||
**status** | [**StatusEnum**](#StatusEnum) | Order Status | [optional]
|
||||
**complete** | **Boolean** | | [optional]
|
||||
|
||||
|
||||
@@ -190,9 +190,9 @@
|
||||
<version>${gson-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.threeten</groupId>
|
||||
<artifactId>threetenbp</artifactId>
|
||||
<version>${threetenbp-version}</version>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>${jodatime-version}</version>
|
||||
</dependency>
|
||||
<!-- Needed for Parcelable support-->
|
||||
<dependency>
|
||||
@@ -216,7 +216,7 @@
|
||||
<swagger-core-version>1.5.15</swagger-core-version>
|
||||
<okhttp-version>2.7.5</okhttp-version>
|
||||
<gson-version>2.8.1</gson-version>
|
||||
<threetenbp-version>1.3.5</threetenbp-version>
|
||||
<jodatime-version>2.9.9</jodatime-version>
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
<junit-version>4.12</junit-version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
@@ -19,9 +19,9 @@ import com.squareup.okhttp.logging.HttpLoggingInterceptor;
|
||||
import com.squareup.okhttp.logging.HttpLoggingInterceptor.Level;
|
||||
import okio.BufferedSink;
|
||||
import okio.Okio;
|
||||
import org.threeten.bp.LocalDate;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.threeten.bp.format.DateTimeFormatter;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
import java.io.File;
|
||||
@@ -232,8 +232,8 @@ public class ApiClient {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ApiClient setOffsetDateTimeFormat(DateTimeFormatter dateFormat) {
|
||||
this.json.setOffsetDateTimeFormat(dateFormat);
|
||||
public ApiClient setDateTimeFormat(DateTimeFormatter dateFormat) {
|
||||
this.json.setDateTimeFormat(dateFormat);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -447,7 +447,7 @@ public class ApiClient {
|
||||
public String parameterToString(Object param) {
|
||||
if (param == null) {
|
||||
return "";
|
||||
} else if (param instanceof Date || param instanceof OffsetDateTime || param instanceof LocalDate) {
|
||||
} else if (param instanceof Date || param instanceof DateTime || param instanceof LocalDate) {
|
||||
//Serialize to json string and remove the " enclosing characters
|
||||
String jsonStr = json.serialize(param);
|
||||
return jsonStr.substring(1, jsonStr.length() - 1);
|
||||
|
||||
@@ -20,9 +20,10 @@ 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 org.threeten.bp.LocalDate;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.threeten.bp.format.DateTimeFormatter;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
import org.joda.time.format.ISODateTimeFormat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
@@ -37,14 +38,14 @@ public class JSON {
|
||||
private boolean isLenientOnJson = false;
|
||||
private DateTypeAdapter dateTypeAdapter = new DateTypeAdapter();
|
||||
private SqlDateTypeAdapter sqlDateTypeAdapter = new SqlDateTypeAdapter();
|
||||
private OffsetDateTimeTypeAdapter offsetDateTimeTypeAdapter = new OffsetDateTimeTypeAdapter();
|
||||
private DateTimeTypeAdapter dateTimeTypeAdapter = new DateTimeTypeAdapter();
|
||||
private LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter();
|
||||
|
||||
public JSON() {
|
||||
gson = new GsonBuilder()
|
||||
.registerTypeAdapter(Date.class, dateTypeAdapter)
|
||||
.registerTypeAdapter(java.sql.Date.class, sqlDateTypeAdapter)
|
||||
.registerTypeAdapter(OffsetDateTime.class, offsetDateTimeTypeAdapter)
|
||||
.registerTypeAdapter(DateTime.class, dateTimeTypeAdapter)
|
||||
.registerTypeAdapter(LocalDate.class, localDateTypeAdapter)
|
||||
.create();
|
||||
}
|
||||
@@ -113,17 +114,18 @@ public class JSON {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gson TypeAdapter for JSR310 OffsetDateTime type
|
||||
* Gson TypeAdapter for Joda DateTime type
|
||||
*/
|
||||
public static class OffsetDateTimeTypeAdapter extends TypeAdapter<OffsetDateTime> {
|
||||
public static class DateTimeTypeAdapter extends TypeAdapter<DateTime> {
|
||||
|
||||
private DateTimeFormatter formatter;
|
||||
private final DateTimeFormatter parseFormatter = ISODateTimeFormat.dateOptionalTimeParser();
|
||||
private final DateTimeFormatter printFormatter = ISODateTimeFormat.dateTime();
|
||||
|
||||
public OffsetDateTimeTypeAdapter() {
|
||||
this(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
|
||||
public DateTimeTypeAdapter() {
|
||||
this(ISODateTimeFormat.dateTime().withOffsetParsed());
|
||||
}
|
||||
|
||||
public OffsetDateTimeTypeAdapter(DateTimeFormatter formatter) {
|
||||
public DateTimeTypeAdapter(DateTimeFormatter formatter) {
|
||||
this.formatter = formatter;
|
||||
}
|
||||
|
||||
@@ -132,39 +134,36 @@ public class JSON {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(JsonWriter out, OffsetDateTime date) throws IOException {
|
||||
public void write(JsonWriter out, DateTime date) throws IOException {
|
||||
if (date == null) {
|
||||
out.nullValue();
|
||||
} else {
|
||||
out.value(formatter.format(date));
|
||||
out.value(printFormatter.print(date));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public OffsetDateTime read(JsonReader in) throws IOException {
|
||||
public DateTime read(JsonReader in) throws IOException {
|
||||
switch (in.peek()) {
|
||||
case NULL:
|
||||
in.nextNull();
|
||||
return null;
|
||||
default:
|
||||
String date = in.nextString();
|
||||
if (date.endsWith("+0000")) {
|
||||
date = date.substring(0, date.length()-5) + "Z";
|
||||
}
|
||||
return OffsetDateTime.parse(date, formatter);
|
||||
return parseFormatter.parseDateTime(date);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gson TypeAdapter for JSR310 LocalDate type
|
||||
* Gson TypeAdapter for Joda LocalDate type
|
||||
*/
|
||||
public class LocalDateTypeAdapter extends TypeAdapter<LocalDate> {
|
||||
|
||||
private DateTimeFormatter formatter;
|
||||
|
||||
public LocalDateTypeAdapter() {
|
||||
this(DateTimeFormatter.ISO_LOCAL_DATE);
|
||||
this(ISODateTimeFormat.date());
|
||||
}
|
||||
|
||||
public LocalDateTypeAdapter(DateTimeFormatter formatter) {
|
||||
@@ -180,7 +179,7 @@ public class JSON {
|
||||
if (date == null) {
|
||||
out.nullValue();
|
||||
} else {
|
||||
out.value(formatter.format(date));
|
||||
out.value(formatter.print(date));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,13 +191,13 @@ public class JSON {
|
||||
return null;
|
||||
default:
|
||||
String date = in.nextString();
|
||||
return LocalDate.parse(date, formatter);
|
||||
return formatter.parseLocalDate(date);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public JSON setOffsetDateTimeFormat(DateTimeFormatter dateFormat) {
|
||||
offsetDateTimeTypeAdapter.setFormat(dateFormat);
|
||||
public JSON setDateTimeFormat(DateTimeFormatter dateFormat) {
|
||||
dateTimeTypeAdapter.setFormat(dateFormat);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ import java.io.IOException;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import io.swagger.client.model.Client;
|
||||
import org.threeten.bp.LocalDate;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
import io.swagger.client.model.OuterComposite;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
@@ -689,7 +689,7 @@ public class FakeApi {
|
||||
* @return Call to execute
|
||||
* @throws ApiException If fail to serialize the request body object
|
||||
*/
|
||||
public com.squareup.okhttp.Call testEndpointParametersCall(BigDecimal number, Double _double, String patternWithoutDelimiter, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, String string, byte[] binary, LocalDate date, OffsetDateTime dateTime, String password, String paramCallback, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
|
||||
public com.squareup.okhttp.Call testEndpointParametersCall(BigDecimal number, Double _double, String patternWithoutDelimiter, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, String string, byte[] binary, LocalDate date, DateTime dateTime, String password, String paramCallback, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
|
||||
Object localVarPostBody = null;
|
||||
|
||||
// create path and map variables
|
||||
@@ -759,7 +759,7 @@ public class FakeApi {
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private com.squareup.okhttp.Call testEndpointParametersValidateBeforeCall(BigDecimal number, Double _double, String patternWithoutDelimiter, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, String string, byte[] binary, LocalDate date, OffsetDateTime dateTime, String password, String paramCallback, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
|
||||
private com.squareup.okhttp.Call testEndpointParametersValidateBeforeCall(BigDecimal number, Double _double, String patternWithoutDelimiter, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, String string, byte[] binary, LocalDate date, DateTime dateTime, String password, String paramCallback, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
|
||||
|
||||
// verify the required parameter 'number' is set
|
||||
if (number == null) {
|
||||
@@ -810,7 +810,7 @@ public class FakeApi {
|
||||
* @param paramCallback None (optional)
|
||||
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
|
||||
*/
|
||||
public void testEndpointParameters(BigDecimal number, Double _double, String patternWithoutDelimiter, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, String string, byte[] binary, LocalDate date, OffsetDateTime dateTime, String password, String paramCallback) throws ApiException {
|
||||
public void testEndpointParameters(BigDecimal number, Double _double, String patternWithoutDelimiter, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, String string, byte[] binary, LocalDate date, DateTime dateTime, String password, String paramCallback) throws ApiException {
|
||||
testEndpointParametersWithHttpInfo(number, _double, patternWithoutDelimiter, _byte, integer, int32, int64, _float, string, binary, date, dateTime, password, paramCallback);
|
||||
}
|
||||
|
||||
@@ -834,7 +834,7 @@ public class FakeApi {
|
||||
* @return ApiResponse<Void>
|
||||
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
|
||||
*/
|
||||
public ApiResponse<Void> testEndpointParametersWithHttpInfo(BigDecimal number, Double _double, String patternWithoutDelimiter, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, String string, byte[] binary, LocalDate date, OffsetDateTime dateTime, String password, String paramCallback) throws ApiException {
|
||||
public ApiResponse<Void> testEndpointParametersWithHttpInfo(BigDecimal number, Double _double, String patternWithoutDelimiter, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, String string, byte[] binary, LocalDate date, DateTime dateTime, String password, String paramCallback) throws ApiException {
|
||||
com.squareup.okhttp.Call call = testEndpointParametersValidateBeforeCall(number, _double, patternWithoutDelimiter, _byte, integer, int32, int64, _float, string, binary, date, dateTime, password, paramCallback, null, null);
|
||||
return apiClient.execute(call);
|
||||
}
|
||||
@@ -860,7 +860,7 @@ public class FakeApi {
|
||||
* @return The request call
|
||||
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
|
||||
*/
|
||||
public com.squareup.okhttp.Call testEndpointParametersAsync(BigDecimal number, Double _double, String patternWithoutDelimiter, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, String string, byte[] binary, LocalDate date, OffsetDateTime dateTime, String password, String paramCallback, final ApiCallback<Void> callback) throws ApiException {
|
||||
public com.squareup.okhttp.Call testEndpointParametersAsync(BigDecimal number, Double _double, String patternWithoutDelimiter, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, String string, byte[] binary, LocalDate date, DateTime dateTime, String password, String paramCallback, final ApiCallback<Void> callback) throws ApiException {
|
||||
|
||||
ProgressResponseBody.ProgressListener progressListener = null;
|
||||
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
|
||||
|
||||
@@ -24,8 +24,8 @@ import io.swagger.annotations.ApiModelProperty;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.UUID;
|
||||
import org.threeten.bp.LocalDate;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
import android.os.Parcelable;
|
||||
import android.os.Parcel;
|
||||
|
||||
@@ -65,7 +65,7 @@ public class FormatTest implements Parcelable {
|
||||
private LocalDate date = null;
|
||||
|
||||
@SerializedName("dateTime")
|
||||
private OffsetDateTime dateTime = null;
|
||||
private DateTime dateTime = null;
|
||||
|
||||
@SerializedName("uuid")
|
||||
private UUID uuid = null;
|
||||
@@ -263,7 +263,7 @@ public class FormatTest implements Parcelable {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public FormatTest dateTime(OffsetDateTime dateTime) {
|
||||
public FormatTest dateTime(DateTime dateTime) {
|
||||
this.dateTime = dateTime;
|
||||
return this;
|
||||
}
|
||||
@@ -273,11 +273,11 @@ public class FormatTest implements Parcelable {
|
||||
* @return dateTime
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public OffsetDateTime getDateTime() {
|
||||
public DateTime getDateTime() {
|
||||
return dateTime;
|
||||
}
|
||||
|
||||
public void setDateTime(OffsetDateTime dateTime) {
|
||||
public void setDateTime(DateTime dateTime) {
|
||||
this.dateTime = dateTime;
|
||||
}
|
||||
|
||||
@@ -426,7 +426,7 @@ public class FormatTest implements Parcelable {
|
||||
_byte = (byte[])in.readValue(null);
|
||||
binary = (byte[])in.readValue(null);
|
||||
date = (LocalDate)in.readValue(LocalDate.class.getClassLoader());
|
||||
dateTime = (OffsetDateTime)in.readValue(OffsetDateTime.class.getClassLoader());
|
||||
dateTime = (DateTime)in.readValue(DateTime.class.getClassLoader());
|
||||
uuid = (UUID)in.readValue(UUID.class.getClassLoader());
|
||||
password = (String)in.readValue(null);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.joda.time.DateTime;
|
||||
import android.os.Parcelable;
|
||||
import android.os.Parcel;
|
||||
|
||||
@@ -40,7 +40,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass implements Parcelable {
|
||||
private UUID uuid = null;
|
||||
|
||||
@SerializedName("dateTime")
|
||||
private OffsetDateTime dateTime = null;
|
||||
private DateTime dateTime = null;
|
||||
|
||||
@SerializedName("map")
|
||||
private Map<String, Animal> map = null;
|
||||
@@ -63,7 +63,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass implements Parcelable {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public MixedPropertiesAndAdditionalPropertiesClass dateTime(OffsetDateTime dateTime) {
|
||||
public MixedPropertiesAndAdditionalPropertiesClass dateTime(DateTime dateTime) {
|
||||
this.dateTime = dateTime;
|
||||
return this;
|
||||
}
|
||||
@@ -73,11 +73,11 @@ public class MixedPropertiesAndAdditionalPropertiesClass implements Parcelable {
|
||||
* @return dateTime
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public OffsetDateTime getDateTime() {
|
||||
public DateTime getDateTime() {
|
||||
return dateTime;
|
||||
}
|
||||
|
||||
public void setDateTime(OffsetDateTime dateTime) {
|
||||
public void setDateTime(DateTime dateTime) {
|
||||
this.dateTime = dateTime;
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass implements Parcelable {
|
||||
MixedPropertiesAndAdditionalPropertiesClass(Parcel in) {
|
||||
|
||||
uuid = (UUID)in.readValue(UUID.class.getClassLoader());
|
||||
dateTime = (OffsetDateTime)in.readValue(OffsetDateTime.class.getClassLoader());
|
||||
dateTime = (DateTime)in.readValue(DateTime.class.getClassLoader());
|
||||
map = (Map<String, Animal>)in.readValue(Animal.class.getClassLoader());
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import com.google.gson.stream.JsonWriter;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import java.io.IOException;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.joda.time.DateTime;
|
||||
import android.os.Parcelable;
|
||||
import android.os.Parcel;
|
||||
|
||||
@@ -41,7 +41,7 @@ public class Order implements Parcelable {
|
||||
private Integer quantity = null;
|
||||
|
||||
@SerializedName("shipDate")
|
||||
private OffsetDateTime shipDate = null;
|
||||
private DateTime shipDate = null;
|
||||
|
||||
/**
|
||||
* Order Status
|
||||
@@ -152,7 +152,7 @@ public class Order implements Parcelable {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public Order shipDate(OffsetDateTime shipDate) {
|
||||
public Order shipDate(DateTime shipDate) {
|
||||
this.shipDate = shipDate;
|
||||
return this;
|
||||
}
|
||||
@@ -162,11 +162,11 @@ public class Order implements Parcelable {
|
||||
* @return shipDate
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public OffsetDateTime getShipDate() {
|
||||
public DateTime getShipDate() {
|
||||
return shipDate;
|
||||
}
|
||||
|
||||
public void setShipDate(OffsetDateTime shipDate) {
|
||||
public void setShipDate(DateTime shipDate) {
|
||||
this.shipDate = shipDate;
|
||||
}
|
||||
|
||||
@@ -280,7 +280,7 @@ public class Order implements Parcelable {
|
||||
id = (Long)in.readValue(null);
|
||||
petId = (Long)in.readValue(null);
|
||||
quantity = (Integer)in.readValue(null);
|
||||
shipDate = (OffsetDateTime)in.readValue(OffsetDateTime.class.getClassLoader());
|
||||
shipDate = (DateTime)in.readValue(DateTime.class.getClassLoader());
|
||||
status = (StatusEnum)in.readValue(null);
|
||||
complete = (Boolean)in.readValue(null);
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
2.3.0-SNAPSHOT
|
||||
2.2.3-SNAPSHOT
|
||||
@@ -98,6 +98,6 @@ dependencies {
|
||||
compile 'com.squareup.okhttp:okhttp:2.7.5'
|
||||
compile 'com.squareup.okhttp:logging-interceptor:2.7.5'
|
||||
compile 'com.google.code.gson:gson:2.8.1'
|
||||
compile 'org.threeten:threetenbp:1.3.5'
|
||||
compile 'joda-time:joda-time:2.9.9'
|
||||
testCompile 'junit:junit:4.12'
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ lazy val root = (project in file(".")).
|
||||
"com.squareup.okhttp" % "okhttp" % "2.7.5",
|
||||
"com.squareup.okhttp" % "logging-interceptor" % "2.7.5",
|
||||
"com.google.code.gson" % "gson" % "2.8.1",
|
||||
"org.threeten" % "threetenbp" % "1.3.5" % "compile",
|
||||
"joda-time" % "joda-time" % "2.9.9" % "compile",
|
||||
"junit" % "junit" % "4.12" % "test",
|
||||
"com.novocode" % "junit-interface" % "0.10" % "test"
|
||||
)
|
||||
|
||||
@@ -275,7 +275,7 @@ Float _float = 3.4F; // Float | None
|
||||
String string = "string_example"; // String | None
|
||||
byte[] binary = B; // byte[] | None
|
||||
LocalDate date = new LocalDate(); // LocalDate | None
|
||||
OffsetDateTime dateTime = new OffsetDateTime(); // OffsetDateTime | None
|
||||
DateTime dateTime = new DateTime(); // DateTime | None
|
||||
String password = "password_example"; // String | None
|
||||
String paramCallback = "paramCallback_example"; // String | None
|
||||
try {
|
||||
@@ -301,7 +301,7 @@ Name | Type | Description | Notes
|
||||
**string** | **String**| None | [optional]
|
||||
**binary** | **byte[]**| None | [optional]
|
||||
**date** | **LocalDate**| None | [optional]
|
||||
**dateTime** | **OffsetDateTime**| None | [optional]
|
||||
**dateTime** | **DateTime**| None | [optional]
|
||||
**password** | **String**| None | [optional]
|
||||
**paramCallback** | **String**| None | [optional]
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ Name | Type | Description | Notes
|
||||
**_byte** | **byte[]** | |
|
||||
**binary** | **byte[]** | | [optional]
|
||||
**date** | [**LocalDate**](LocalDate.md) | |
|
||||
**dateTime** | [**OffsetDateTime**](OffsetDateTime.md) | | [optional]
|
||||
**dateTime** | [**DateTime**](DateTime.md) | | [optional]
|
||||
**uuid** | [**UUID**](UUID.md) | | [optional]
|
||||
**password** | **String** | |
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**uuid** | [**UUID**](UUID.md) | | [optional]
|
||||
**dateTime** | [**OffsetDateTime**](OffsetDateTime.md) | | [optional]
|
||||
**dateTime** | [**DateTime**](DateTime.md) | | [optional]
|
||||
**map** | [**Map<String, Animal>**](Animal.md) | | [optional]
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ Name | Type | Description | Notes
|
||||
**id** | **Long** | | [optional]
|
||||
**petId** | **Long** | | [optional]
|
||||
**quantity** | **Integer** | | [optional]
|
||||
**shipDate** | [**OffsetDateTime**](OffsetDateTime.md) | | [optional]
|
||||
**shipDate** | [**DateTime**](DateTime.md) | | [optional]
|
||||
**status** | [**StatusEnum**](#StatusEnum) | Order Status | [optional]
|
||||
**complete** | **Boolean** | | [optional]
|
||||
|
||||
|
||||
@@ -190,9 +190,9 @@
|
||||
<version>${gson-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.threeten</groupId>
|
||||
<artifactId>threetenbp</artifactId>
|
||||
<version>${threetenbp-version}</version>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>${jodatime-version}</version>
|
||||
</dependency>
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
@@ -209,7 +209,7 @@
|
||||
<swagger-core-version>1.5.15</swagger-core-version>
|
||||
<okhttp-version>2.7.5</okhttp-version>
|
||||
<gson-version>2.8.1</gson-version>
|
||||
<threetenbp-version>1.3.5</threetenbp-version>
|
||||
<jodatime-version>2.9.9</jodatime-version>
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
<junit-version>4.12</junit-version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
@@ -19,9 +19,9 @@ import com.squareup.okhttp.logging.HttpLoggingInterceptor;
|
||||
import com.squareup.okhttp.logging.HttpLoggingInterceptor.Level;
|
||||
import okio.BufferedSink;
|
||||
import okio.Okio;
|
||||
import org.threeten.bp.LocalDate;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.threeten.bp.format.DateTimeFormatter;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
import java.io.File;
|
||||
@@ -232,8 +232,8 @@ public class ApiClient {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ApiClient setOffsetDateTimeFormat(DateTimeFormatter dateFormat) {
|
||||
this.json.setOffsetDateTimeFormat(dateFormat);
|
||||
public ApiClient setDateTimeFormat(DateTimeFormatter dateFormat) {
|
||||
this.json.setDateTimeFormat(dateFormat);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -447,7 +447,7 @@ public class ApiClient {
|
||||
public String parameterToString(Object param) {
|
||||
if (param == null) {
|
||||
return "";
|
||||
} else if (param instanceof Date || param instanceof OffsetDateTime || param instanceof LocalDate) {
|
||||
} else if (param instanceof Date || param instanceof DateTime || param instanceof LocalDate) {
|
||||
//Serialize to json string and remove the " enclosing characters
|
||||
String jsonStr = json.serialize(param);
|
||||
return jsonStr.substring(1, jsonStr.length() - 1);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user