From 40369bb81951e446e5fc8692d042284c3937145e Mon Sep 17 00:00:00 2001 From: Jordan Zimmerman Date: Sat, 1 Jul 2017 02:04:18 -0500 Subject: [PATCH] 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 --- .../languages/AbstractJavaCodegen.java | 23 +- .../Java/auth/HttpBasicAuth.mustache | 13 + .../main/resources/Java/build.gradle.mustache | 2 + .../libraries/jersey2/build.gradle.mustache | 2 + .../Java/libraries/jersey2/build.sbt.mustache | 2 + .../Java/libraries/jersey2/pom.mustache | 2 + .../libraries/resteasy/build.gradle.mustache | 2 +- .../libraries/resteasy/build.sbt.mustache | 2 +- .../Java/libraries/resteasy/pom.mustache | 3 +- .../src/main/resources/Java/pom.mustache | 2 + .../codegen/options/JavaOptionsProvider.java | 2 + .../options/JaxRSServerOptionsProvider.java | 2 + .../libraries/jersey2/build.gradle.mustache | 2 +- .../Java/libraries/jersey2/build.sbt.mustache | 2 +- .../Java/libraries/jersey2/pom.mustache | 3 +- .../java/okhttp-gson/build.gradle | 6 +- .../java/okhttp-gson/build.sbt | 6 +- .../java/okhttp-gson/pom.xml | 4 +- .../java/io/swagger/client/ApiClient.java | 397 +++++------------- .../src/main/java/io/swagger/client/JSON.java | 385 +++++++++++------ .../java/io/swagger/client/api/FakeApi.java | 3 +- .../java/feign/.swagger-codegen/VERSION | 2 +- .../client/petstore/java/feign/build.gradle | 3 +- samples/client/petstore/java/feign/pom.xml | 9 +- .../java/io/swagger/client/ApiClient.java | 9 +- .../client/CustomInstantDeserializer.java | 232 ---------- .../java/io/swagger/client/api/FakeApi.java | 6 +- .../io/swagger/client/model/FormatTest.java | 12 +- ...ropertiesAndAdditionalPropertiesClass.java | 10 +- .../java/io/swagger/client/model/Order.java | 10 +- .../java/jersey1/.swagger-codegen/VERSION | 2 +- .../client/petstore/java/jersey1/build.gradle | 4 +- .../petstore/java/jersey1/docs/FakeApi.md | 4 +- .../petstore/java/jersey1/docs/FormatTest.md | 2 +- ...dPropertiesAndAdditionalPropertiesClass.md | 2 +- .../petstore/java/jersey1/docs/Order.md | 2 +- samples/client/petstore/java/jersey1/pom.xml | 6 +- .../java/io/swagger/client/ApiClient.java | 10 +- .../client/CustomInstantDeserializer.java | 232 ---------- .../java/io/swagger/client/api/FakeApi.java | 6 +- .../io/swagger/client/model/FormatTest.java | 12 +- ...ropertiesAndAdditionalPropertiesClass.java | 10 +- .../java/io/swagger/client/model/Order.java | 10 +- .../jersey2-java6/.swagger-codegen/VERSION | 2 +- .../petstore/java/jersey2-java6/build.gradle | 6 +- .../petstore/java/jersey2-java6/build.sbt | 9 +- .../java/jersey2-java6/docs/FakeApi.md | 4 +- .../java/jersey2-java6/docs/FormatTest.md | 2 +- ...dPropertiesAndAdditionalPropertiesClass.md | 2 +- .../petstore/java/jersey2-java6/docs/Order.md | 2 +- .../petstore/java/jersey2-java6/pom.xml | 13 +- .../client/CustomInstantDeserializer.java | 232 ---------- .../src/main/java/io/swagger/client/JSON.java | 9 +- .../java/io/swagger/client/api/FakeApi.java | 6 +- .../io/swagger/client/model/FormatTest.java | 12 +- ...ropertiesAndAdditionalPropertiesClass.java | 10 +- .../java/io/swagger/client/model/Order.java | 10 +- .../jersey2-java8/.swagger-codegen/VERSION | 2 +- .../petstore/java/jersey2-java8/build.gradle | 3 +- .../petstore/java/jersey2-java8/build.sbt | 8 +- .../petstore/java/jersey2-java8/pom.xml | 8 +- .../src/main/java/io/swagger/client/JSON.java | 2 +- .../io/swagger/client/auth/HttpBasicAuth.java | 10 +- .../java/jersey2/.swagger-codegen/VERSION | 2 +- .../client/petstore/java/jersey2/build.gradle | 4 +- .../client/petstore/java/jersey2/build.sbt | 9 +- .../petstore/java/jersey2/docs/FakeApi.md | 4 +- .../petstore/java/jersey2/docs/FormatTest.md | 2 +- ...dPropertiesAndAdditionalPropertiesClass.md | 2 +- .../petstore/java/jersey2/docs/Order.md | 2 +- samples/client/petstore/java/jersey2/pom.xml | 13 +- .../client/CustomInstantDeserializer.java | 232 ---------- .../src/main/java/io/swagger/client/JSON.java | 9 +- .../java/io/swagger/client/api/FakeApi.java | 6 +- .../io/swagger/client/model/FormatTest.java | 12 +- ...ropertiesAndAdditionalPropertiesClass.java | 10 +- .../java/io/swagger/client/model/Order.java | 10 +- .../.swagger-codegen/VERSION | 2 +- .../okhttp-gson-parcelableModel/build.gradle | 2 +- .../okhttp-gson-parcelableModel/build.sbt | 2 +- .../docs/FakeApi.md | 4 +- .../docs/FormatTest.md | 2 +- ...dPropertiesAndAdditionalPropertiesClass.md | 2 +- .../okhttp-gson-parcelableModel/docs/Order.md | 2 +- .../java/okhttp-gson-parcelableModel/pom.xml | 8 +- .../java/io/swagger/client/ApiClient.java | 12 +- .../src/main/java/io/swagger/client/JSON.java | 47 +-- .../java/io/swagger/client/api/FakeApi.java | 14 +- .../io/swagger/client/model/FormatTest.java | 14 +- ...ropertiesAndAdditionalPropertiesClass.java | 12 +- .../java/io/swagger/client/model/Order.java | 12 +- .../java/okhttp-gson/.swagger-codegen/VERSION | 2 +- .../petstore/java/okhttp-gson/build.gradle | 2 +- .../petstore/java/okhttp-gson/build.sbt | 2 +- .../petstore/java/okhttp-gson/docs/FakeApi.md | 4 +- .../java/okhttp-gson/docs/FormatTest.md | 2 +- ...dPropertiesAndAdditionalPropertiesClass.md | 2 +- .../petstore/java/okhttp-gson/docs/Order.md | 2 +- .../client/petstore/java/okhttp-gson/pom.xml | 8 +- .../java/io/swagger/client/ApiClient.java | 12 +- .../src/main/java/io/swagger/client/JSON.java | 47 +-- .../java/io/swagger/client/api/FakeApi.java | 14 +- .../io/swagger/client/model/FormatTest.java | 12 +- ...ropertiesAndAdditionalPropertiesClass.java | 10 +- .../java/io/swagger/client/model/Order.java | 10 +- .../java/resteasy/.swagger-codegen/VERSION | 2 +- .../petstore/java/resteasy/docs/FakeApi.md | 4 +- .../petstore/java/resteasy/docs/FormatTest.md | 2 +- ...dPropertiesAndAdditionalPropertiesClass.md | 2 +- .../petstore/java/resteasy/docs/Order.md | 2 +- samples/client/petstore/java/resteasy/pom.xml | 1 + .../client/CustomInstantDeserializer.java | 232 ---------- .../java/io/swagger/client/api/FakeApi.java | 6 +- .../io/swagger/client/model/FormatTest.java | 12 +- ...ropertiesAndAdditionalPropertiesClass.java | 10 +- .../java/io/swagger/client/model/Order.java | 10 +- .../resttemplate/.swagger-codegen/VERSION | 2 +- .../petstore/java/resttemplate/build.gradle | 4 +- .../java/resttemplate/docs/FakeApi.md | 4 +- .../java/resttemplate/docs/FormatTest.md | 2 +- ...dPropertiesAndAdditionalPropertiesClass.md | 2 +- .../petstore/java/resttemplate/docs/Order.md | 2 +- .../client/petstore/java/resttemplate/pom.xml | 13 +- .../java/io/swagger/client/ApiClient.java | 21 - .../client/CustomInstantDeserializer.java | 232 ---------- .../java/io/swagger/client/api/FakeApi.java | 6 +- .../io/swagger/client/model/FormatTest.java | 12 +- ...ropertiesAndAdditionalPropertiesClass.java | 10 +- .../java/io/swagger/client/model/Order.java | 10 +- .../java/retrofit/.swagger-codegen/VERSION | 2 +- .../retrofit2-play24/.swagger-codegen/VERSION | 2 +- .../java/retrofit2-play24/build.gradle | 4 +- .../petstore/java/retrofit2-play24/build.sbt | 2 +- .../java/retrofit2-play24/docs/FakeApi.md | 4 +- .../java/retrofit2-play24/docs/FormatTest.md | 2 +- ...dPropertiesAndAdditionalPropertiesClass.md | 2 +- .../java/retrofit2-play24/docs/Order.md | 2 +- .../petstore/java/retrofit2-play24/pom.xml | 8 +- .../client/CustomInstantDeserializer.java | 232 ---------- .../src/main/java/io/swagger/client/JSON.java | 289 ------------- .../java/io/swagger/client/api/FakeApi.java | 8 +- .../client/api/FakeClassnameTags123Api.java | 2 + .../java/io/swagger/client/api/PetApi.java | 2 + .../java/io/swagger/client/api/StoreApi.java | 2 + .../java/io/swagger/client/api/UserApi.java | 2 + .../io/swagger/client/model/FormatTest.java | 12 +- ...ropertiesAndAdditionalPropertiesClass.java | 10 +- .../java/io/swagger/client/model/Order.java | 10 +- .../java/retrofit2/.swagger-codegen/VERSION | 2 +- .../petstore/java/retrofit2/build.gradle | 4 +- .../client/petstore/java/retrofit2/build.sbt | 2 +- .../petstore/java/retrofit2/docs/FakeApi.md | 4 +- .../java/retrofit2/docs/FormatTest.md | 2 +- ...dPropertiesAndAdditionalPropertiesClass.md | 2 +- .../petstore/java/retrofit2/docs/Order.md | 2 +- .../client/petstore/java/retrofit2/pom.xml | 8 +- .../java/io/swagger/client/ApiClient.java | 6 +- .../src/main/java/io/swagger/client/JSON.java | 289 ------------- .../java/io/swagger/client/api/FakeApi.java | 6 +- .../io/swagger/client/model/FormatTest.java | 12 +- ...ropertiesAndAdditionalPropertiesClass.java | 10 +- .../java/io/swagger/client/model/Order.java | 10 +- .../java/retrofit2rx/.swagger-codegen/VERSION | 2 +- .../petstore/java/retrofit2rx/build.gradle | 4 +- .../petstore/java/retrofit2rx/build.sbt | 2 +- .../petstore/java/retrofit2rx/docs/FakeApi.md | 4 +- .../java/retrofit2rx/docs/FormatTest.md | 2 +- ...dPropertiesAndAdditionalPropertiesClass.md | 2 +- .../petstore/java/retrofit2rx/docs/Order.md | 2 +- .../client/petstore/java/retrofit2rx/pom.xml | 8 +- .../java/io/swagger/client/ApiClient.java | 6 +- .../src/main/java/io/swagger/client/JSON.java | 289 ------------- .../java/io/swagger/client/api/FakeApi.java | 6 +- .../io/swagger/client/model/FormatTest.java | 12 +- ...ropertiesAndAdditionalPropertiesClass.java | 10 +- .../java/io/swagger/client/model/Order.java | 10 +- .../retrofit2rx2/.swagger-codegen/VERSION | 2 +- .../petstore/java/retrofit2rx2/build.gradle | 4 +- .../petstore/java/retrofit2rx2/build.sbt | 2 +- .../java/retrofit2rx2/docs/FakeApi.md | 4 +- .../java/retrofit2rx2/docs/FormatTest.md | 2 +- ...dPropertiesAndAdditionalPropertiesClass.md | 2 +- .../petstore/java/retrofit2rx2/docs/Order.md | 2 +- .../client/petstore/java/retrofit2rx2/pom.xml | 8 +- .../java/io/swagger/client/ApiClient.java | 6 +- .../src/main/java/io/swagger/client/JSON.java | 289 ------------- .../java/io/swagger/client/api/FakeApi.java | 6 +- .../io/swagger/client/model/FormatTest.java | 12 +- ...ropertiesAndAdditionalPropertiesClass.java | 10 +- .../java/io/swagger/client/model/Order.java | 10 +- 190 files changed, 913 insertions(+), 3757 deletions(-) delete mode 100644 samples/client/petstore/java/feign/src/main/java/io/swagger/client/CustomInstantDeserializer.java delete mode 100644 samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/CustomInstantDeserializer.java delete mode 100644 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/CustomInstantDeserializer.java delete mode 100644 samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/CustomInstantDeserializer.java delete mode 100644 samples/client/petstore/java/resteasy/src/main/java/io/swagger/client/CustomInstantDeserializer.java delete mode 100644 samples/client/petstore/java/resttemplate/src/main/java/io/swagger/client/CustomInstantDeserializer.java delete mode 100644 samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/CustomInstantDeserializer.java delete mode 100644 samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/JSON.java delete mode 100644 samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/JSON.java delete mode 100644 samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/JSON.java delete mode 100644 samples/client/petstore/java/retrofit2rx2/src/main/java/io/swagger/client/JSON.java diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractJavaCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractJavaCodegen.java index 3f9806109e..07e6a9ecc5 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractJavaCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractJavaCodegen.java @@ -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 = ""; 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 dateOptions = new HashMap(); - 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 java8ModeOptions = new HashMap(); + 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 diff --git a/modules/swagger-codegen/src/main/resources/Java/auth/HttpBasicAuth.mustache b/modules/swagger-codegen/src/main/resources/Java/auth/HttpBasicAuth.mustache index 0438f6a40b..015e042e17 100644 --- a/modules/swagger-codegen/src/main/resources/Java/auth/HttpBasicAuth.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/auth/HttpBasicAuth.mustache @@ -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}} } } diff --git a/modules/swagger-codegen/src/main/resources/Java/build.gradle.mustache b/modules/swagger-codegen/src/main/resources/Java/build.gradle.mustache index 785baab787..6c05fd5a36 100644 --- a/modules/swagger-codegen/src/main/resources/Java/build.gradle.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/build.gradle.mustache @@ -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" } diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/build.gradle.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/build.gradle.mustache index 755298212c..8394d1253e 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/build.gradle.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/build.gradle.mustache @@ -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" } diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/build.sbt.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/build.sbt.mustache index e5579b67ea..ba6f9e36e5 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/build.sbt.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/build.sbt.mustache @@ -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", diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/pom.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/pom.mustache index 10d0751e04..b885c4ef26 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/pom.mustache @@ -244,12 +244,14 @@ {{/threetenbp}} + {{^java8}} com.brsanthu migbase64 2.2 + {{/java8}} {{#supportJava6}} org.apache.commons diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/resteasy/build.gradle.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/resteasy/build.gradle.mustache index e150b8671e..5a8e29157a 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/resteasy/build.gradle.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/resteasy/build.gradle.mustache @@ -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" } diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/resteasy/build.sbt.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/resteasy/build.sbt.mustache index c1cb91dd31..348d29d96d 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/resteasy/build.sbt.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/resteasy/build.sbt.mustache @@ -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", diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/resteasy/pom.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/resteasy/pom.mustache index ffea816e21..bd22192d14 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/resteasy/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/resteasy/pom.mustache @@ -168,7 +168,6 @@ joda-time ${jodatime-version} - {{/java8}} @@ -176,6 +175,8 @@ migbase64 2.2 + {{/java8}} + {{#supportJava6}} org.apache.commons diff --git a/modules/swagger-codegen/src/main/resources/Java/pom.mustache b/modules/swagger-codegen/src/main/resources/Java/pom.mustache index da0ea1c986..8f7b67b205 100644 --- a/modules/swagger-codegen/src/main/resources/Java/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/pom.mustache @@ -245,12 +245,14 @@ {{/threetenbp}} + {{^java8}} com.brsanthu migbase64 2.2 + {{/java8}} {{#supportJava6}} diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JavaOptionsProvider.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JavaOptionsProvider.java index eb60599435..5ba2417b50 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JavaOptionsProvider.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JavaOptionsProvider.java @@ -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") diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JaxRSServerOptionsProvider.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JaxRSServerOptionsProvider.java index ce89ee75ec..535c637a4c 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JaxRSServerOptionsProvider.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JaxRSServerOptionsProvider.java @@ -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) diff --git a/modules/swagger-codegen/src/test/resources/2_0/templates/Java/libraries/jersey2/build.gradle.mustache b/modules/swagger-codegen/src/test/resources/2_0/templates/Java/libraries/jersey2/build.gradle.mustache index 739287b28c..b6d2dd8ec3 100644 --- a/modules/swagger-codegen/src/test/resources/2_0/templates/Java/libraries/jersey2/build.gradle.mustache +++ b/modules/swagger-codegen/src/test/resources/2_0/templates/Java/libraries/jersey2/build.gradle.mustache @@ -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" } diff --git a/modules/swagger-codegen/src/test/resources/2_0/templates/Java/libraries/jersey2/build.sbt.mustache b/modules/swagger-codegen/src/test/resources/2_0/templates/Java/libraries/jersey2/build.sbt.mustache index b2d31d23f7..cce1667464 100644 --- a/modules/swagger-codegen/src/test/resources/2_0/templates/Java/libraries/jersey2/build.sbt.mustache +++ b/modules/swagger-codegen/src/test/resources/2_0/templates/Java/libraries/jersey2/build.sbt.mustache @@ -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", diff --git a/modules/swagger-codegen/src/test/resources/2_0/templates/Java/libraries/jersey2/pom.mustache b/modules/swagger-codegen/src/test/resources/2_0/templates/Java/libraries/jersey2/pom.mustache index 4972cb349c..6b3dc78938 100644 --- a/modules/swagger-codegen/src/test/resources/2_0/templates/Java/libraries/jersey2/pom.mustache +++ b/modules/swagger-codegen/src/test/resources/2_0/templates/Java/libraries/jersey2/pom.mustache @@ -242,7 +242,6 @@ joda-time ${jodatime-version} - {{/java8}} @@ -250,6 +249,8 @@ migbase64 2.2 + {{/java8}} + {{#supportJava6}} org.apache.commons diff --git a/samples/client/petstore-security-test/java/okhttp-gson/build.gradle b/samples/client/petstore-security-test/java/okhttp-gson/build.gradle index 0f403ed63f..1d7eb55f31 100644 --- a/samples/client/petstore-security-test/java/okhttp-gson/build.gradle +++ b/samples/client/petstore-security-test/java/okhttp-gson/build.gradle @@ -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' } diff --git a/samples/client/petstore-security-test/java/okhttp-gson/build.sbt b/samples/client/petstore-security-test/java/okhttp-gson/build.sbt index 01a1095f8a..0cb2e94994 100644 --- a/samples/client/petstore-security-test/java/okhttp-gson/build.sbt +++ b/samples/client/petstore-security-test/java/okhttp-gson/build.sbt @@ -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" ) diff --git a/samples/client/petstore-security-test/java/okhttp-gson/pom.xml b/samples/client/petstore-security-test/java/okhttp-gson/pom.xml index dbd7942c97..00d2187628 100644 --- a/samples/client/petstore-security-test/java/okhttp-gson/pom.xml +++ b/samples/client/petstore-security-test/java/okhttp-gson/pom.xml @@ -208,8 +208,8 @@ ${java.version} 1.5.15 2.7.5 - 2.6.2 - 2.9.3 + 2.8.1 + 2.9.9 1.0.0 4.12 UTF-8 diff --git a/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java index ba8bdfbc25..76f285a3a5 100644 --- a/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java @@ -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 lenientDatetimeFormat 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 defaultHeaderMap = new HashMap(); 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 parseDatetime. - 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 dateFormat 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 ISO 8601 - * @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 LENIENT_DATETIME_FORMAT 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 setLenient - * - * @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 parameterToPairs(String collectionFormat, String name, Object value){ + public List parameterToPair(String name, Object value) { List params = new ArrayList(); // 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 parameterToPairs(String collectionFormat, String name, Collection value) { + List params = new ArrayList(); + + // 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 queryParams, Object body, Map headerParams, Map 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 queryParams, List collectionQueryParams, Object body, Map headerParams, Map 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 queryParams, Object body, Map headerParams, Map formParams, String[] authNames, ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { + public Request buildRequest(String path, String method, List queryParams, List collectionQueryParams, Object body, Map headerParams, Map 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 queryParams) { + public String buildUrl(String path, List queryParams, List 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. diff --git a/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/JSON.java b/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/JSON.java index 43b8be5d60..720f9c91ce 100644 --- a/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/JSON.java +++ b/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/JSON.java @@ -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 Type - * @param body The JSON string + * @param Type + * @param body The JSON string * @param returnType The type to deserialize into * @return The deserialized Java object */ @SuppressWarnings("unchecked") public 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, JsonDeserializer { - 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 { - - 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 { - - 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 { + + 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 { + + 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 { + + 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 { + + 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; + } + } diff --git a/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/api/FakeApi.java b/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/api/FakeApi.java index 40a7942e68..d822adb868 100644 --- a/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/api/FakeApi.java +++ b/samples/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/api/FakeApi.java @@ -68,6 +68,7 @@ public class FakeApi { String localVarPath = "/fake"; List localVarQueryParams = new ArrayList(); + List localVarCollectionQueryParams = new ArrayList(); Map localVarHeaderParams = new HashMap(); @@ -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") diff --git a/samples/client/petstore/java/feign/.swagger-codegen/VERSION b/samples/client/petstore/java/feign/.swagger-codegen/VERSION index f9f7450d13..7fea99011a 100644 --- a/samples/client/petstore/java/feign/.swagger-codegen/VERSION +++ b/samples/client/petstore/java/feign/.swagger-codegen/VERSION @@ -1 +1 @@ -2.3.0-SNAPSHOT \ No newline at end of file +2.2.3-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/java/feign/build.gradle b/samples/client/petstore/java/feign/build.gradle index 2a538aa20a..9f2accb79f 100644 --- a/samples/client/petstore/java/feign/build.gradle +++ b/samples/client/petstore/java/feign/build.gradle @@ -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" diff --git a/samples/client/petstore/java/feign/pom.xml b/samples/client/petstore/java/feign/pom.xml index 8abcc8d6bf..165ceec4c9 100644 --- a/samples/client/petstore/java/feign/pom.xml +++ b/samples/client/petstore/java/feign/pom.xml @@ -213,9 +213,9 @@ ${jackson-version} - com.github.joschi.jackson - jackson-datatype-threetenbp - ${jackson-threetenbp-version} + com.fasterxml.jackson.datatype + jackson-datatype-joda + ${jackson-version} org.apache.oltu.oauth2 @@ -250,8 +250,7 @@ 1.5.15 9.4.0 2.1.0 - 2.8.9 - 2.6.4 + 2.8.7 4.12 1.0.0 1.0.1 diff --git a/samples/client/petstore/java/feign/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/feign/src/main/java/io/swagger/client/ApiClient.java index 9c646d6e8f..d487cb1059 100644 --- a/samples/client/petstore/java/feign/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/feign/src/main/java/io/swagger/client/ApiClient.java @@ -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; } diff --git a/samples/client/petstore/java/feign/src/main/java/io/swagger/client/CustomInstantDeserializer.java b/samples/client/petstore/java/feign/src/main/java/io/swagger/client/CustomInstantDeserializer.java deleted file mode 100644 index 5ed8ba446e..0000000000 --- a/samples/client/petstore/java/feign/src/main/java/io/swagger/client/CustomInstantDeserializer.java +++ /dev/null @@ -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 - extends ThreeTenDateTimeDeserializerBase { - private static final long serialVersionUID = 1L; - - public static final CustomInstantDeserializer INSTANT = new CustomInstantDeserializer( - Instant.class, DateTimeFormatter.ISO_INSTANT, - new Function() { - @Override - public Instant apply(TemporalAccessor temporalAccessor) { - return Instant.from(temporalAccessor); - } - }, - new Function() { - @Override - public Instant apply(FromIntegerArguments a) { - return Instant.ofEpochMilli(a.value); - } - }, - new Function() { - @Override - public Instant apply(FromDecimalArguments a) { - return Instant.ofEpochSecond(a.integer, a.fraction); - } - }, - null - ); - - public static final CustomInstantDeserializer OFFSET_DATE_TIME = new CustomInstantDeserializer( - OffsetDateTime.class, DateTimeFormatter.ISO_OFFSET_DATE_TIME, - new Function() { - @Override - public OffsetDateTime apply(TemporalAccessor temporalAccessor) { - return OffsetDateTime.from(temporalAccessor); - } - }, - new Function() { - @Override - public OffsetDateTime apply(FromIntegerArguments a) { - return OffsetDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId); - } - }, - new Function() { - @Override - public OffsetDateTime apply(FromDecimalArguments a) { - return OffsetDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId); - } - }, - new BiFunction() { - @Override - public OffsetDateTime apply(OffsetDateTime d, ZoneId z) { - return d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime())); - } - } - ); - - public static final CustomInstantDeserializer ZONED_DATE_TIME = new CustomInstantDeserializer( - ZonedDateTime.class, DateTimeFormatter.ISO_ZONED_DATE_TIME, - new Function() { - @Override - public ZonedDateTime apply(TemporalAccessor temporalAccessor) { - return ZonedDateTime.from(temporalAccessor); - } - }, - new Function() { - @Override - public ZonedDateTime apply(FromIntegerArguments a) { - return ZonedDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId); - } - }, - new Function() { - @Override - public ZonedDateTime apply(FromDecimalArguments a) { - return ZonedDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId); - } - }, - new BiFunction() { - @Override - public ZonedDateTime apply(ZonedDateTime zonedDateTime, ZoneId zoneId) { - return zonedDateTime.withZoneSameInstant(zoneId); - } - } - ); - - protected final Function fromMilliseconds; - - protected final Function fromNanoseconds; - - protected final Function parsedToValue; - - protected final BiFunction adjust; - - protected CustomInstantDeserializer(Class supportedType, - DateTimeFormatter parser, - Function parsedToValue, - Function fromMilliseconds, - Function fromNanoseconds, - BiFunction adjust) { - super(supportedType, parser); - this.parsedToValue = parsedToValue; - this.fromMilliseconds = fromMilliseconds; - this.fromNanoseconds = fromNanoseconds; - this.adjust = adjust == null ? new BiFunction() { - @Override - public T apply(T t, ZoneId zoneId) { - return t; - } - } : adjust; - } - - @SuppressWarnings("unchecked") - protected CustomInstantDeserializer(CustomInstantDeserializer base, DateTimeFormatter f) { - super((Class) base.handledType(), f); - parsedToValue = base.parsedToValue; - fromMilliseconds = base.fromMilliseconds; - fromNanoseconds = base.fromNanoseconds; - adjust = base.adjust; - } - - @Override - protected JsonDeserializer withDateFormat(DateTimeFormatter dtf) { - if (dtf == _formatter) { - return this; - } - return new CustomInstantDeserializer(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; - } - } -} diff --git a/samples/client/petstore/java/feign/src/main/java/io/swagger/client/api/FakeApi.java b/samples/client/petstore/java/feign/src/main/java/io/swagger/client/api/FakeApi.java index b757d44bbe..3737b8286c 100644 --- a/samples/client/petstore/java/feign/src/main/java/io/swagger/client/api/FakeApi.java +++ b/samples/client/petstore/java/feign/src/main/java/io/swagger/client/api/FakeApi.java @@ -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 diff --git a/samples/client/petstore/java/feign/src/main/java/io/swagger/client/model/FormatTest.java b/samples/client/petstore/java/feign/src/main/java/io/swagger/client/model/FormatTest.java index 3897095d84..c2aa5f35fe 100644 --- a/samples/client/petstore/java/feign/src/main/java/io/swagger/client/model/FormatTest.java +++ b/samples/client/petstore/java/feign/src/main/java/io/swagger/client/model/FormatTest.java @@ -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; } diff --git a/samples/client/petstore/java/feign/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java b/samples/client/petstore/java/feign/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java index 229669da93..9cd0ca678b 100644 --- a/samples/client/petstore/java/feign/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java +++ b/samples/client/petstore/java/feign/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java @@ -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 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; } diff --git a/samples/client/petstore/java/feign/src/main/java/io/swagger/client/model/Order.java b/samples/client/petstore/java/feign/src/main/java/io/swagger/client/model/Order.java index 2edfd83b31..d08d27721a 100644 --- a/samples/client/petstore/java/feign/src/main/java/io/swagger/client/model/Order.java +++ b/samples/client/petstore/java/feign/src/main/java/io/swagger/client/model/Order.java @@ -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; } diff --git a/samples/client/petstore/java/jersey1/.swagger-codegen/VERSION b/samples/client/petstore/java/jersey1/.swagger-codegen/VERSION index f9f7450d13..7fea99011a 100644 --- a/samples/client/petstore/java/jersey1/.swagger-codegen/VERSION +++ b/samples/client/petstore/java/jersey1/.swagger-codegen/VERSION @@ -1 +1 @@ -2.3.0-SNAPSHOT \ No newline at end of file +2.2.3-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/java/jersey1/build.gradle b/samples/client/petstore/java/jersey1/build.gradle index 1845b51a5d..fca05cc630 100644 --- a/samples/client/petstore/java/jersey1/build.gradle +++ b/samples/client/petstore/java/jersey1/build.gradle @@ -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" } diff --git a/samples/client/petstore/java/jersey1/docs/FakeApi.md b/samples/client/petstore/java/jersey1/docs/FakeApi.md index 79aed327d1..5a061d3e6b 100644 --- a/samples/client/petstore/java/jersey1/docs/FakeApi.md +++ b/samples/client/petstore/java/jersey1/docs/FakeApi.md @@ -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] diff --git a/samples/client/petstore/java/jersey1/docs/FormatTest.md b/samples/client/petstore/java/jersey1/docs/FormatTest.md index c7a3acb3cb..06bed41723 100644 --- a/samples/client/petstore/java/jersey1/docs/FormatTest.md +++ b/samples/client/petstore/java/jersey1/docs/FormatTest.md @@ -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** | | diff --git a/samples/client/petstore/java/jersey1/docs/MixedPropertiesAndAdditionalPropertiesClass.md b/samples/client/petstore/java/jersey1/docs/MixedPropertiesAndAdditionalPropertiesClass.md index b12e2cd70e..349afef35a 100644 --- a/samples/client/petstore/java/jersey1/docs/MixedPropertiesAndAdditionalPropertiesClass.md +++ b/samples/client/petstore/java/jersey1/docs/MixedPropertiesAndAdditionalPropertiesClass.md @@ -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] diff --git a/samples/client/petstore/java/jersey1/docs/Order.md b/samples/client/petstore/java/jersey1/docs/Order.md index 268c617d1f..a1089f5384 100644 --- a/samples/client/petstore/java/jersey1/docs/Order.md +++ b/samples/client/petstore/java/jersey1/docs/Order.md @@ -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] diff --git a/samples/client/petstore/java/jersey1/pom.xml b/samples/client/petstore/java/jersey1/pom.xml index 7a53181da4..152363c688 100644 --- a/samples/client/petstore/java/jersey1/pom.xml +++ b/samples/client/petstore/java/jersey1/pom.xml @@ -218,8 +218,8 @@ ${jackson-version} - com.github.joschi.jackson - jackson-datatype-threetenbp + com.fasterxml.jackson.datatype + jackson-datatype-joda ${jackson-version} @@ -244,7 +244,7 @@ UTF-8 1.5.15 1.19.4 - 2.6.4 + 2.7.5 1.0.0 4.12 diff --git a/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/ApiClient.java index 7a3082bef6..a130296e68 100644 --- a/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/ApiClient.java @@ -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(); diff --git a/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/CustomInstantDeserializer.java b/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/CustomInstantDeserializer.java deleted file mode 100644 index 5ed8ba446e..0000000000 --- a/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/CustomInstantDeserializer.java +++ /dev/null @@ -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 - extends ThreeTenDateTimeDeserializerBase { - private static final long serialVersionUID = 1L; - - public static final CustomInstantDeserializer INSTANT = new CustomInstantDeserializer( - Instant.class, DateTimeFormatter.ISO_INSTANT, - new Function() { - @Override - public Instant apply(TemporalAccessor temporalAccessor) { - return Instant.from(temporalAccessor); - } - }, - new Function() { - @Override - public Instant apply(FromIntegerArguments a) { - return Instant.ofEpochMilli(a.value); - } - }, - new Function() { - @Override - public Instant apply(FromDecimalArguments a) { - return Instant.ofEpochSecond(a.integer, a.fraction); - } - }, - null - ); - - public static final CustomInstantDeserializer OFFSET_DATE_TIME = new CustomInstantDeserializer( - OffsetDateTime.class, DateTimeFormatter.ISO_OFFSET_DATE_TIME, - new Function() { - @Override - public OffsetDateTime apply(TemporalAccessor temporalAccessor) { - return OffsetDateTime.from(temporalAccessor); - } - }, - new Function() { - @Override - public OffsetDateTime apply(FromIntegerArguments a) { - return OffsetDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId); - } - }, - new Function() { - @Override - public OffsetDateTime apply(FromDecimalArguments a) { - return OffsetDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId); - } - }, - new BiFunction() { - @Override - public OffsetDateTime apply(OffsetDateTime d, ZoneId z) { - return d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime())); - } - } - ); - - public static final CustomInstantDeserializer ZONED_DATE_TIME = new CustomInstantDeserializer( - ZonedDateTime.class, DateTimeFormatter.ISO_ZONED_DATE_TIME, - new Function() { - @Override - public ZonedDateTime apply(TemporalAccessor temporalAccessor) { - return ZonedDateTime.from(temporalAccessor); - } - }, - new Function() { - @Override - public ZonedDateTime apply(FromIntegerArguments a) { - return ZonedDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId); - } - }, - new Function() { - @Override - public ZonedDateTime apply(FromDecimalArguments a) { - return ZonedDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId); - } - }, - new BiFunction() { - @Override - public ZonedDateTime apply(ZonedDateTime zonedDateTime, ZoneId zoneId) { - return zonedDateTime.withZoneSameInstant(zoneId); - } - } - ); - - protected final Function fromMilliseconds; - - protected final Function fromNanoseconds; - - protected final Function parsedToValue; - - protected final BiFunction adjust; - - protected CustomInstantDeserializer(Class supportedType, - DateTimeFormatter parser, - Function parsedToValue, - Function fromMilliseconds, - Function fromNanoseconds, - BiFunction adjust) { - super(supportedType, parser); - this.parsedToValue = parsedToValue; - this.fromMilliseconds = fromMilliseconds; - this.fromNanoseconds = fromNanoseconds; - this.adjust = adjust == null ? new BiFunction() { - @Override - public T apply(T t, ZoneId zoneId) { - return t; - } - } : adjust; - } - - @SuppressWarnings("unchecked") - protected CustomInstantDeserializer(CustomInstantDeserializer base, DateTimeFormatter f) { - super((Class) base.handledType(), f); - parsedToValue = base.parsedToValue; - fromMilliseconds = base.fromMilliseconds; - fromNanoseconds = base.fromNanoseconds; - adjust = base.adjust; - } - - @Override - protected JsonDeserializer withDateFormat(DateTimeFormatter dtf) { - if (dtf == _formatter) { - return this; - } - return new CustomInstantDeserializer(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; - } - } -} diff --git a/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/api/FakeApi.java b/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/api/FakeApi.java index f5df2bb813..fe92f95740 100644 --- a/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/api/FakeApi.java +++ b/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/api/FakeApi.java @@ -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 diff --git a/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/model/FormatTest.java b/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/model/FormatTest.java index 3897095d84..c2aa5f35fe 100644 --- a/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/model/FormatTest.java +++ b/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/model/FormatTest.java @@ -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; } diff --git a/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java b/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java index 229669da93..9cd0ca678b 100644 --- a/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java +++ b/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java @@ -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 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; } diff --git a/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/model/Order.java b/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/model/Order.java index 2edfd83b31..d08d27721a 100644 --- a/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/model/Order.java +++ b/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/model/Order.java @@ -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; } diff --git a/samples/client/petstore/java/jersey2-java6/.swagger-codegen/VERSION b/samples/client/petstore/java/jersey2-java6/.swagger-codegen/VERSION index f9f7450d13..7fea99011a 100644 --- a/samples/client/petstore/java/jersey2-java6/.swagger-codegen/VERSION +++ b/samples/client/petstore/java/jersey2-java6/.swagger-codegen/VERSION @@ -1 +1 @@ -2.3.0-SNAPSHOT \ No newline at end of file +2.2.3-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/java/jersey2-java6/build.gradle b/samples/client/petstore/java/jersey2-java6/build.gradle index 866f217218..4809dcd79a 100644 --- a/samples/client/petstore/java/jersey2-java6/build.gradle +++ b/samples/client/petstore/java/jersey2-java6/build.gradle @@ -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" } diff --git a/samples/client/petstore/java/jersey2-java6/build.sbt b/samples/client/petstore/java/jersey2-java6/build.sbt index 164450b9f0..05f502ac4a 100644 --- a/samples/client/petstore/java/jersey2-java6/build.sbt +++ b/samples/client/petstore/java/jersey2-java6/build.sbt @@ -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", diff --git a/samples/client/petstore/java/jersey2-java6/docs/FakeApi.md b/samples/client/petstore/java/jersey2-java6/docs/FakeApi.md index 79aed327d1..5a061d3e6b 100644 --- a/samples/client/petstore/java/jersey2-java6/docs/FakeApi.md +++ b/samples/client/petstore/java/jersey2-java6/docs/FakeApi.md @@ -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] diff --git a/samples/client/petstore/java/jersey2-java6/docs/FormatTest.md b/samples/client/petstore/java/jersey2-java6/docs/FormatTest.md index c7a3acb3cb..06bed41723 100644 --- a/samples/client/petstore/java/jersey2-java6/docs/FormatTest.md +++ b/samples/client/petstore/java/jersey2-java6/docs/FormatTest.md @@ -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** | | diff --git a/samples/client/petstore/java/jersey2-java6/docs/MixedPropertiesAndAdditionalPropertiesClass.md b/samples/client/petstore/java/jersey2-java6/docs/MixedPropertiesAndAdditionalPropertiesClass.md index b12e2cd70e..349afef35a 100644 --- a/samples/client/petstore/java/jersey2-java6/docs/MixedPropertiesAndAdditionalPropertiesClass.md +++ b/samples/client/petstore/java/jersey2-java6/docs/MixedPropertiesAndAdditionalPropertiesClass.md @@ -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] diff --git a/samples/client/petstore/java/jersey2-java6/docs/Order.md b/samples/client/petstore/java/jersey2-java6/docs/Order.md index 268c617d1f..a1089f5384 100644 --- a/samples/client/petstore/java/jersey2-java6/docs/Order.md +++ b/samples/client/petstore/java/jersey2-java6/docs/Order.md @@ -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] diff --git a/samples/client/petstore/java/jersey2-java6/pom.xml b/samples/client/petstore/java/jersey2-java6/pom.xml index b0dbac8392..10c36abe73 100644 --- a/samples/client/petstore/java/jersey2-java6/pom.xml +++ b/samples/client/petstore/java/jersey2-java6/pom.xml @@ -217,10 +217,15 @@ ${jackson-version} - com.github.joschi.jackson - jackson-datatype-threetenbp + com.fasterxml.jackson.datatype + jackson-datatype-joda ${jackson-version} + + joda-time + joda-time + ${jodatime-version} + @@ -228,6 +233,7 @@ migbase64 2.2 + org.apache.commons commons-lang3 @@ -251,9 +257,10 @@ 1.5.15 2.25.1 + 2.8.9 + 2.9.9 2.5 3.6 - 2.6.4 1.0.0 4.12 diff --git a/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/CustomInstantDeserializer.java b/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/CustomInstantDeserializer.java deleted file mode 100644 index 5ed8ba446e..0000000000 --- a/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/CustomInstantDeserializer.java +++ /dev/null @@ -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 - extends ThreeTenDateTimeDeserializerBase { - private static final long serialVersionUID = 1L; - - public static final CustomInstantDeserializer INSTANT = new CustomInstantDeserializer( - Instant.class, DateTimeFormatter.ISO_INSTANT, - new Function() { - @Override - public Instant apply(TemporalAccessor temporalAccessor) { - return Instant.from(temporalAccessor); - } - }, - new Function() { - @Override - public Instant apply(FromIntegerArguments a) { - return Instant.ofEpochMilli(a.value); - } - }, - new Function() { - @Override - public Instant apply(FromDecimalArguments a) { - return Instant.ofEpochSecond(a.integer, a.fraction); - } - }, - null - ); - - public static final CustomInstantDeserializer OFFSET_DATE_TIME = new CustomInstantDeserializer( - OffsetDateTime.class, DateTimeFormatter.ISO_OFFSET_DATE_TIME, - new Function() { - @Override - public OffsetDateTime apply(TemporalAccessor temporalAccessor) { - return OffsetDateTime.from(temporalAccessor); - } - }, - new Function() { - @Override - public OffsetDateTime apply(FromIntegerArguments a) { - return OffsetDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId); - } - }, - new Function() { - @Override - public OffsetDateTime apply(FromDecimalArguments a) { - return OffsetDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId); - } - }, - new BiFunction() { - @Override - public OffsetDateTime apply(OffsetDateTime d, ZoneId z) { - return d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime())); - } - } - ); - - public static final CustomInstantDeserializer ZONED_DATE_TIME = new CustomInstantDeserializer( - ZonedDateTime.class, DateTimeFormatter.ISO_ZONED_DATE_TIME, - new Function() { - @Override - public ZonedDateTime apply(TemporalAccessor temporalAccessor) { - return ZonedDateTime.from(temporalAccessor); - } - }, - new Function() { - @Override - public ZonedDateTime apply(FromIntegerArguments a) { - return ZonedDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId); - } - }, - new Function() { - @Override - public ZonedDateTime apply(FromDecimalArguments a) { - return ZonedDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId); - } - }, - new BiFunction() { - @Override - public ZonedDateTime apply(ZonedDateTime zonedDateTime, ZoneId zoneId) { - return zonedDateTime.withZoneSameInstant(zoneId); - } - } - ); - - protected final Function fromMilliseconds; - - protected final Function fromNanoseconds; - - protected final Function parsedToValue; - - protected final BiFunction adjust; - - protected CustomInstantDeserializer(Class supportedType, - DateTimeFormatter parser, - Function parsedToValue, - Function fromMilliseconds, - Function fromNanoseconds, - BiFunction adjust) { - super(supportedType, parser); - this.parsedToValue = parsedToValue; - this.fromMilliseconds = fromMilliseconds; - this.fromNanoseconds = fromNanoseconds; - this.adjust = adjust == null ? new BiFunction() { - @Override - public T apply(T t, ZoneId zoneId) { - return t; - } - } : adjust; - } - - @SuppressWarnings("unchecked") - protected CustomInstantDeserializer(CustomInstantDeserializer base, DateTimeFormatter f) { - super((Class) base.handledType(), f); - parsedToValue = base.parsedToValue; - fromMilliseconds = base.fromMilliseconds; - fromNanoseconds = base.fromNanoseconds; - adjust = base.adjust; - } - - @Override - protected JsonDeserializer withDateFormat(DateTimeFormatter dtf) { - if (dtf == _formatter) { - return this; - } - return new CustomInstantDeserializer(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; - } - } -} diff --git a/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/JSON.java b/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/JSON.java index 433f1a313e..131b1b34d0 100644 --- a/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/JSON.java +++ b/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/JSON.java @@ -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 { 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()); } /** diff --git a/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/api/FakeApi.java b/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/api/FakeApi.java index f810edcd3d..8aa23a3d18 100644 --- a/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/api/FakeApi.java +++ b/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/api/FakeApi.java @@ -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 diff --git a/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/FormatTest.java b/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/FormatTest.java index 0ed06c2934..78b6cd6b0f 100644 --- a/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/FormatTest.java +++ b/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/FormatTest.java @@ -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; } diff --git a/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java b/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java index 06ff5b6287..6965728b56 100644 --- a/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java +++ b/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java @@ -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 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; } diff --git a/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/Order.java b/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/Order.java index 32de914a76..46a12da6fe 100644 --- a/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/Order.java +++ b/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/Order.java @@ -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; } diff --git a/samples/client/petstore/java/jersey2-java8/.swagger-codegen/VERSION b/samples/client/petstore/java/jersey2-java8/.swagger-codegen/VERSION index f9f7450d13..7fea99011a 100644 --- a/samples/client/petstore/java/jersey2-java8/.swagger-codegen/VERSION +++ b/samples/client/petstore/java/jersey2-java8/.swagger-codegen/VERSION @@ -1 +1 @@ -2.3.0-SNAPSHOT \ No newline at end of file +2.2.3-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/java/jersey2-java8/build.gradle b/samples/client/petstore/java/jersey2-java8/build.gradle index cdf4758199..bf5a6b8d23 100644 --- a/samples/client/petstore/java/jersey2-java8/build.gradle +++ b/samples/client/petstore/java/jersey2-java8/build.gradle @@ -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" } diff --git a/samples/client/petstore/java/jersey2-java8/build.sbt b/samples/client/petstore/java/jersey2-java8/build.sbt index 7375732461..4d2a46846f 100644 --- a/samples/client/petstore/java/jersey2-java8/build.sbt +++ b/samples/client/petstore/java/jersey2-java8/build.sbt @@ -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" diff --git a/samples/client/petstore/java/jersey2-java8/pom.xml b/samples/client/petstore/java/jersey2-java8/pom.xml index e7c38cb532..e244229dd2 100644 --- a/samples/client/petstore/java/jersey2-java8/pom.xml +++ b/samples/client/petstore/java/jersey2-java8/pom.xml @@ -222,12 +222,6 @@ ${jackson-version} - - - com.brsanthu - migbase64 - 2.2 - @@ -240,7 +234,7 @@ 1.5.15 2.25.1 - 2.7.5 + 2.8.9 1.0.0 4.12 diff --git a/samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/JSON.java b/samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/JSON.java index fa10243e54..24503f47ed 100644 --- a/samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/JSON.java +++ b/samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/JSON.java @@ -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; diff --git a/samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/auth/HttpBasicAuth.java b/samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/auth/HttpBasicAuth.java index 788b63a991..0b2a5b4921 100644 --- a/samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/auth/HttpBasicAuth.java +++ b/samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/auth/HttpBasicAuth.java @@ -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))); } } diff --git a/samples/client/petstore/java/jersey2/.swagger-codegen/VERSION b/samples/client/petstore/java/jersey2/.swagger-codegen/VERSION index f9f7450d13..7fea99011a 100644 --- a/samples/client/petstore/java/jersey2/.swagger-codegen/VERSION +++ b/samples/client/petstore/java/jersey2/.swagger-codegen/VERSION @@ -1 +1 @@ -2.3.0-SNAPSHOT \ No newline at end of file +2.2.3-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/java/jersey2/build.gradle b/samples/client/petstore/java/jersey2/build.gradle index 585cdd96a5..2290cd0f1e 100644 --- a/samples/client/petstore/java/jersey2/build.gradle +++ b/samples/client/petstore/java/jersey2/build.gradle @@ -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" } diff --git a/samples/client/petstore/java/jersey2/build.sbt b/samples/client/petstore/java/jersey2/build.sbt index c6d1b92575..9a516c92cf 100644 --- a/samples/client/petstore/java/jersey2/build.sbt +++ b/samples/client/petstore/java/jersey2/build.sbt @@ -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" diff --git a/samples/client/petstore/java/jersey2/docs/FakeApi.md b/samples/client/petstore/java/jersey2/docs/FakeApi.md index 79aed327d1..5a061d3e6b 100644 --- a/samples/client/petstore/java/jersey2/docs/FakeApi.md +++ b/samples/client/petstore/java/jersey2/docs/FakeApi.md @@ -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] diff --git a/samples/client/petstore/java/jersey2/docs/FormatTest.md b/samples/client/petstore/java/jersey2/docs/FormatTest.md index c7a3acb3cb..06bed41723 100644 --- a/samples/client/petstore/java/jersey2/docs/FormatTest.md +++ b/samples/client/petstore/java/jersey2/docs/FormatTest.md @@ -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** | | diff --git a/samples/client/petstore/java/jersey2/docs/MixedPropertiesAndAdditionalPropertiesClass.md b/samples/client/petstore/java/jersey2/docs/MixedPropertiesAndAdditionalPropertiesClass.md index b12e2cd70e..349afef35a 100644 --- a/samples/client/petstore/java/jersey2/docs/MixedPropertiesAndAdditionalPropertiesClass.md +++ b/samples/client/petstore/java/jersey2/docs/MixedPropertiesAndAdditionalPropertiesClass.md @@ -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] diff --git a/samples/client/petstore/java/jersey2/docs/Order.md b/samples/client/petstore/java/jersey2/docs/Order.md index 268c617d1f..a1089f5384 100644 --- a/samples/client/petstore/java/jersey2/docs/Order.md +++ b/samples/client/petstore/java/jersey2/docs/Order.md @@ -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] diff --git a/samples/client/petstore/java/jersey2/pom.xml b/samples/client/petstore/java/jersey2/pom.xml index 7f3206f687..2b114d13bb 100644 --- a/samples/client/petstore/java/jersey2/pom.xml +++ b/samples/client/petstore/java/jersey2/pom.xml @@ -217,10 +217,15 @@ ${jackson-version} - com.github.joschi.jackson - jackson-datatype-threetenbp + com.fasterxml.jackson.datatype + jackson-datatype-joda ${jackson-version} + + joda-time + joda-time + ${jodatime-version} + @@ -229,6 +234,7 @@ 2.2 + junit @@ -240,7 +246,8 @@ 1.5.15 2.25.1 - 2.6.4 + 2.8.9 + 2.9.9 1.0.0 4.12 diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/CustomInstantDeserializer.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/CustomInstantDeserializer.java deleted file mode 100644 index 5ed8ba446e..0000000000 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/CustomInstantDeserializer.java +++ /dev/null @@ -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 - extends ThreeTenDateTimeDeserializerBase { - private static final long serialVersionUID = 1L; - - public static final CustomInstantDeserializer INSTANT = new CustomInstantDeserializer( - Instant.class, DateTimeFormatter.ISO_INSTANT, - new Function() { - @Override - public Instant apply(TemporalAccessor temporalAccessor) { - return Instant.from(temporalAccessor); - } - }, - new Function() { - @Override - public Instant apply(FromIntegerArguments a) { - return Instant.ofEpochMilli(a.value); - } - }, - new Function() { - @Override - public Instant apply(FromDecimalArguments a) { - return Instant.ofEpochSecond(a.integer, a.fraction); - } - }, - null - ); - - public static final CustomInstantDeserializer OFFSET_DATE_TIME = new CustomInstantDeserializer( - OffsetDateTime.class, DateTimeFormatter.ISO_OFFSET_DATE_TIME, - new Function() { - @Override - public OffsetDateTime apply(TemporalAccessor temporalAccessor) { - return OffsetDateTime.from(temporalAccessor); - } - }, - new Function() { - @Override - public OffsetDateTime apply(FromIntegerArguments a) { - return OffsetDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId); - } - }, - new Function() { - @Override - public OffsetDateTime apply(FromDecimalArguments a) { - return OffsetDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId); - } - }, - new BiFunction() { - @Override - public OffsetDateTime apply(OffsetDateTime d, ZoneId z) { - return d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime())); - } - } - ); - - public static final CustomInstantDeserializer ZONED_DATE_TIME = new CustomInstantDeserializer( - ZonedDateTime.class, DateTimeFormatter.ISO_ZONED_DATE_TIME, - new Function() { - @Override - public ZonedDateTime apply(TemporalAccessor temporalAccessor) { - return ZonedDateTime.from(temporalAccessor); - } - }, - new Function() { - @Override - public ZonedDateTime apply(FromIntegerArguments a) { - return ZonedDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId); - } - }, - new Function() { - @Override - public ZonedDateTime apply(FromDecimalArguments a) { - return ZonedDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId); - } - }, - new BiFunction() { - @Override - public ZonedDateTime apply(ZonedDateTime zonedDateTime, ZoneId zoneId) { - return zonedDateTime.withZoneSameInstant(zoneId); - } - } - ); - - protected final Function fromMilliseconds; - - protected final Function fromNanoseconds; - - protected final Function parsedToValue; - - protected final BiFunction adjust; - - protected CustomInstantDeserializer(Class supportedType, - DateTimeFormatter parser, - Function parsedToValue, - Function fromMilliseconds, - Function fromNanoseconds, - BiFunction adjust) { - super(supportedType, parser); - this.parsedToValue = parsedToValue; - this.fromMilliseconds = fromMilliseconds; - this.fromNanoseconds = fromNanoseconds; - this.adjust = adjust == null ? new BiFunction() { - @Override - public T apply(T t, ZoneId zoneId) { - return t; - } - } : adjust; - } - - @SuppressWarnings("unchecked") - protected CustomInstantDeserializer(CustomInstantDeserializer base, DateTimeFormatter f) { - super((Class) base.handledType(), f); - parsedToValue = base.parsedToValue; - fromMilliseconds = base.fromMilliseconds; - fromNanoseconds = base.fromNanoseconds; - adjust = base.adjust; - } - - @Override - protected JsonDeserializer withDateFormat(DateTimeFormatter dtf) { - if (dtf == _formatter) { - return this; - } - return new CustomInstantDeserializer(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; - } - } -} diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/JSON.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/JSON.java index 433f1a313e..131b1b34d0 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/JSON.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/JSON.java @@ -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 { 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()); } /** diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/FakeApi.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/FakeApi.java index f810edcd3d..8aa23a3d18 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/FakeApi.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/FakeApi.java @@ -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 diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/FormatTest.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/FormatTest.java index 3897095d84..c2aa5f35fe 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/FormatTest.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/FormatTest.java @@ -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; } diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java index 229669da93..9cd0ca678b 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java @@ -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 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; } diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Order.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Order.java index 2edfd83b31..d08d27721a 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Order.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Order.java @@ -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; } diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/.swagger-codegen/VERSION b/samples/client/petstore/java/okhttp-gson-parcelableModel/.swagger-codegen/VERSION index f9f7450d13..7fea99011a 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/.swagger-codegen/VERSION +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/.swagger-codegen/VERSION @@ -1 +1 @@ -2.3.0-SNAPSHOT \ No newline at end of file +2.2.3-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/build.gradle b/samples/client/petstore/java/okhttp-gson-parcelableModel/build.gradle index 534d477792..1d7eb55f31 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/build.gradle +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/build.gradle @@ -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' } diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/build.sbt b/samples/client/petstore/java/okhttp-gson-parcelableModel/build.sbt index 03c3ac9e23..0cb2e94994 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/build.sbt +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/build.sbt @@ -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" ) diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/docs/FakeApi.md b/samples/client/petstore/java/okhttp-gson-parcelableModel/docs/FakeApi.md index 79aed327d1..5a061d3e6b 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/docs/FakeApi.md +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/docs/FakeApi.md @@ -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] diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/docs/FormatTest.md b/samples/client/petstore/java/okhttp-gson-parcelableModel/docs/FormatTest.md index c7a3acb3cb..06bed41723 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/docs/FormatTest.md +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/docs/FormatTest.md @@ -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** | | diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/docs/MixedPropertiesAndAdditionalPropertiesClass.md b/samples/client/petstore/java/okhttp-gson-parcelableModel/docs/MixedPropertiesAndAdditionalPropertiesClass.md index b12e2cd70e..349afef35a 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/docs/MixedPropertiesAndAdditionalPropertiesClass.md +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/docs/MixedPropertiesAndAdditionalPropertiesClass.md @@ -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] diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/docs/Order.md b/samples/client/petstore/java/okhttp-gson-parcelableModel/docs/Order.md index 268c617d1f..a1089f5384 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/docs/Order.md +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/docs/Order.md @@ -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] diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/pom.xml b/samples/client/petstore/java/okhttp-gson-parcelableModel/pom.xml index 2872b10b6e..50033a2724 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/pom.xml +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/pom.xml @@ -190,9 +190,9 @@ ${gson-version} - org.threeten - threetenbp - ${threetenbp-version} + joda-time + joda-time + ${jodatime-version} @@ -216,7 +216,7 @@ 1.5.15 2.7.5 2.8.1 - 1.3.5 + 2.9.9 1.0.0 4.12 UTF-8 diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/ApiClient.java index 0a2fa40147..2fb48fb052 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/ApiClient.java @@ -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); diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/JSON.java b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/JSON.java index 992df6a322..8e60a605aa 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/JSON.java +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/JSON.java @@ -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 { + public static class DateTimeTypeAdapter extends TypeAdapter { - 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 { 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; } diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/api/FakeApi.java b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/api/FakeApi.java index 6cf5cae059..221a4e10fb 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/api/FakeApi.java +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/api/FakeApi.java @@ -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 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 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 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 callback) throws ApiException { ProgressResponseBody.ProgressListener progressListener = null; ProgressRequestBody.ProgressRequestListener progressRequestListener = null; diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/model/FormatTest.java b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/model/FormatTest.java index 2c7916197a..59b8e20979 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/model/FormatTest.java +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/model/FormatTest.java @@ -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); } diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java index 5fb3022b01..a24a92f3ea 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java @@ -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 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)in.readValue(Animal.class.getClassLoader()); } diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/model/Order.java b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/model/Order.java index b53b9e204a..35860186d1 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/model/Order.java +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/model/Order.java @@ -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); } diff --git a/samples/client/petstore/java/okhttp-gson/.swagger-codegen/VERSION b/samples/client/petstore/java/okhttp-gson/.swagger-codegen/VERSION index f9f7450d13..7fea99011a 100644 --- a/samples/client/petstore/java/okhttp-gson/.swagger-codegen/VERSION +++ b/samples/client/petstore/java/okhttp-gson/.swagger-codegen/VERSION @@ -1 +1 @@ -2.3.0-SNAPSHOT \ No newline at end of file +2.2.3-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/java/okhttp-gson/build.gradle b/samples/client/petstore/java/okhttp-gson/build.gradle index 534d477792..1d7eb55f31 100644 --- a/samples/client/petstore/java/okhttp-gson/build.gradle +++ b/samples/client/petstore/java/okhttp-gson/build.gradle @@ -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' } diff --git a/samples/client/petstore/java/okhttp-gson/build.sbt b/samples/client/petstore/java/okhttp-gson/build.sbt index 03c3ac9e23..0cb2e94994 100644 --- a/samples/client/petstore/java/okhttp-gson/build.sbt +++ b/samples/client/petstore/java/okhttp-gson/build.sbt @@ -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" ) diff --git a/samples/client/petstore/java/okhttp-gson/docs/FakeApi.md b/samples/client/petstore/java/okhttp-gson/docs/FakeApi.md index 79aed327d1..5a061d3e6b 100644 --- a/samples/client/petstore/java/okhttp-gson/docs/FakeApi.md +++ b/samples/client/petstore/java/okhttp-gson/docs/FakeApi.md @@ -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] diff --git a/samples/client/petstore/java/okhttp-gson/docs/FormatTest.md b/samples/client/petstore/java/okhttp-gson/docs/FormatTest.md index c7a3acb3cb..06bed41723 100644 --- a/samples/client/petstore/java/okhttp-gson/docs/FormatTest.md +++ b/samples/client/petstore/java/okhttp-gson/docs/FormatTest.md @@ -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** | | diff --git a/samples/client/petstore/java/okhttp-gson/docs/MixedPropertiesAndAdditionalPropertiesClass.md b/samples/client/petstore/java/okhttp-gson/docs/MixedPropertiesAndAdditionalPropertiesClass.md index b12e2cd70e..349afef35a 100644 --- a/samples/client/petstore/java/okhttp-gson/docs/MixedPropertiesAndAdditionalPropertiesClass.md +++ b/samples/client/petstore/java/okhttp-gson/docs/MixedPropertiesAndAdditionalPropertiesClass.md @@ -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] diff --git a/samples/client/petstore/java/okhttp-gson/docs/Order.md b/samples/client/petstore/java/okhttp-gson/docs/Order.md index 268c617d1f..a1089f5384 100644 --- a/samples/client/petstore/java/okhttp-gson/docs/Order.md +++ b/samples/client/petstore/java/okhttp-gson/docs/Order.md @@ -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] diff --git a/samples/client/petstore/java/okhttp-gson/pom.xml b/samples/client/petstore/java/okhttp-gson/pom.xml index a161bd1205..d9cf3f47c3 100644 --- a/samples/client/petstore/java/okhttp-gson/pom.xml +++ b/samples/client/petstore/java/okhttp-gson/pom.xml @@ -190,9 +190,9 @@ ${gson-version} - org.threeten - threetenbp - ${threetenbp-version} + joda-time + joda-time + ${jodatime-version} @@ -209,7 +209,7 @@ 1.5.15 2.7.5 2.8.1 - 1.3.5 + 2.9.9 1.0.0 4.12 UTF-8 diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java index 0a2fa40147..2fb48fb052 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java @@ -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); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/JSON.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/JSON.java index 992df6a322..8e60a605aa 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/JSON.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/JSON.java @@ -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 { + public static class DateTimeTypeAdapter extends TypeAdapter { - 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 { 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; } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/FakeApi.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/FakeApi.java index 6cf5cae059..221a4e10fb 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/FakeApi.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/FakeApi.java @@ -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 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 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 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 callback) throws ApiException { ProgressResponseBody.ProgressListener progressListener = null; ProgressRequestBody.ProgressRequestListener progressRequestListener = null; diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/FormatTest.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/FormatTest.java index bd87692a36..8ec80fccb7 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/FormatTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/FormatTest.java @@ -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; /** * FormatTest @@ -63,7 +63,7 @@ public class FormatTest { private LocalDate date = null; @SerializedName("dateTime") - private OffsetDateTime dateTime = null; + private DateTime dateTime = null; @SerializedName("uuid") private UUID uuid = null; @@ -261,7 +261,7 @@ public class FormatTest { this.date = date; } - public FormatTest dateTime(OffsetDateTime dateTime) { + public FormatTest dateTime(DateTime dateTime) { this.dateTime = dateTime; return this; } @@ -271,11 +271,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; } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java index 9c92756e16..447501906d 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java @@ -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; /** * MixedPropertiesAndAdditionalPropertiesClass @@ -38,7 +38,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass { private UUID uuid = null; @SerializedName("dateTime") - private OffsetDateTime dateTime = null; + private DateTime dateTime = null; @SerializedName("map") private Map map = null; @@ -61,7 +61,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass { this.uuid = uuid; } - public MixedPropertiesAndAdditionalPropertiesClass dateTime(OffsetDateTime dateTime) { + public MixedPropertiesAndAdditionalPropertiesClass dateTime(DateTime dateTime) { this.dateTime = dateTime; return this; } @@ -71,11 +71,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; } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/Order.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/Order.java index 7856f4baf7..3249680760 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/Order.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/Order.java @@ -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; /** * Order @@ -39,7 +39,7 @@ public class Order { private Integer quantity = null; @SerializedName("shipDate") - private OffsetDateTime shipDate = null; + private DateTime shipDate = null; /** * Order Status @@ -150,7 +150,7 @@ public class Order { this.quantity = quantity; } - public Order shipDate(OffsetDateTime shipDate) { + public Order shipDate(DateTime shipDate) { this.shipDate = shipDate; return this; } @@ -160,11 +160,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; } diff --git a/samples/client/petstore/java/resteasy/.swagger-codegen/VERSION b/samples/client/petstore/java/resteasy/.swagger-codegen/VERSION index f9f7450d13..7fea99011a 100644 --- a/samples/client/petstore/java/resteasy/.swagger-codegen/VERSION +++ b/samples/client/petstore/java/resteasy/.swagger-codegen/VERSION @@ -1 +1 @@ -2.3.0-SNAPSHOT \ No newline at end of file +2.2.3-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/java/resteasy/docs/FakeApi.md b/samples/client/petstore/java/resteasy/docs/FakeApi.md index 79aed327d1..5a061d3e6b 100644 --- a/samples/client/petstore/java/resteasy/docs/FakeApi.md +++ b/samples/client/petstore/java/resteasy/docs/FakeApi.md @@ -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] diff --git a/samples/client/petstore/java/resteasy/docs/FormatTest.md b/samples/client/petstore/java/resteasy/docs/FormatTest.md index c7a3acb3cb..06bed41723 100644 --- a/samples/client/petstore/java/resteasy/docs/FormatTest.md +++ b/samples/client/petstore/java/resteasy/docs/FormatTest.md @@ -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** | | diff --git a/samples/client/petstore/java/resteasy/docs/MixedPropertiesAndAdditionalPropertiesClass.md b/samples/client/petstore/java/resteasy/docs/MixedPropertiesAndAdditionalPropertiesClass.md index b12e2cd70e..349afef35a 100644 --- a/samples/client/petstore/java/resteasy/docs/MixedPropertiesAndAdditionalPropertiesClass.md +++ b/samples/client/petstore/java/resteasy/docs/MixedPropertiesAndAdditionalPropertiesClass.md @@ -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] diff --git a/samples/client/petstore/java/resteasy/docs/Order.md b/samples/client/petstore/java/resteasy/docs/Order.md index 268c617d1f..a1089f5384 100644 --- a/samples/client/petstore/java/resteasy/docs/Order.md +++ b/samples/client/petstore/java/resteasy/docs/Order.md @@ -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] diff --git a/samples/client/petstore/java/resteasy/pom.xml b/samples/client/petstore/java/resteasy/pom.xml index aba73d0ed9..a08daa851f 100644 --- a/samples/client/petstore/java/resteasy/pom.xml +++ b/samples/client/petstore/java/resteasy/pom.xml @@ -161,6 +161,7 @@ migbase64 2.2 + org.jboss.resteasy resteasy-jackson-provider diff --git a/samples/client/petstore/java/resteasy/src/main/java/io/swagger/client/CustomInstantDeserializer.java b/samples/client/petstore/java/resteasy/src/main/java/io/swagger/client/CustomInstantDeserializer.java deleted file mode 100644 index 5ed8ba446e..0000000000 --- a/samples/client/petstore/java/resteasy/src/main/java/io/swagger/client/CustomInstantDeserializer.java +++ /dev/null @@ -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 - extends ThreeTenDateTimeDeserializerBase { - private static final long serialVersionUID = 1L; - - public static final CustomInstantDeserializer INSTANT = new CustomInstantDeserializer( - Instant.class, DateTimeFormatter.ISO_INSTANT, - new Function() { - @Override - public Instant apply(TemporalAccessor temporalAccessor) { - return Instant.from(temporalAccessor); - } - }, - new Function() { - @Override - public Instant apply(FromIntegerArguments a) { - return Instant.ofEpochMilli(a.value); - } - }, - new Function() { - @Override - public Instant apply(FromDecimalArguments a) { - return Instant.ofEpochSecond(a.integer, a.fraction); - } - }, - null - ); - - public static final CustomInstantDeserializer OFFSET_DATE_TIME = new CustomInstantDeserializer( - OffsetDateTime.class, DateTimeFormatter.ISO_OFFSET_DATE_TIME, - new Function() { - @Override - public OffsetDateTime apply(TemporalAccessor temporalAccessor) { - return OffsetDateTime.from(temporalAccessor); - } - }, - new Function() { - @Override - public OffsetDateTime apply(FromIntegerArguments a) { - return OffsetDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId); - } - }, - new Function() { - @Override - public OffsetDateTime apply(FromDecimalArguments a) { - return OffsetDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId); - } - }, - new BiFunction() { - @Override - public OffsetDateTime apply(OffsetDateTime d, ZoneId z) { - return d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime())); - } - } - ); - - public static final CustomInstantDeserializer ZONED_DATE_TIME = new CustomInstantDeserializer( - ZonedDateTime.class, DateTimeFormatter.ISO_ZONED_DATE_TIME, - new Function() { - @Override - public ZonedDateTime apply(TemporalAccessor temporalAccessor) { - return ZonedDateTime.from(temporalAccessor); - } - }, - new Function() { - @Override - public ZonedDateTime apply(FromIntegerArguments a) { - return ZonedDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId); - } - }, - new Function() { - @Override - public ZonedDateTime apply(FromDecimalArguments a) { - return ZonedDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId); - } - }, - new BiFunction() { - @Override - public ZonedDateTime apply(ZonedDateTime zonedDateTime, ZoneId zoneId) { - return zonedDateTime.withZoneSameInstant(zoneId); - } - } - ); - - protected final Function fromMilliseconds; - - protected final Function fromNanoseconds; - - protected final Function parsedToValue; - - protected final BiFunction adjust; - - protected CustomInstantDeserializer(Class supportedType, - DateTimeFormatter parser, - Function parsedToValue, - Function fromMilliseconds, - Function fromNanoseconds, - BiFunction adjust) { - super(supportedType, parser); - this.parsedToValue = parsedToValue; - this.fromMilliseconds = fromMilliseconds; - this.fromNanoseconds = fromNanoseconds; - this.adjust = adjust == null ? new BiFunction() { - @Override - public T apply(T t, ZoneId zoneId) { - return t; - } - } : adjust; - } - - @SuppressWarnings("unchecked") - protected CustomInstantDeserializer(CustomInstantDeserializer base, DateTimeFormatter f) { - super((Class) base.handledType(), f); - parsedToValue = base.parsedToValue; - fromMilliseconds = base.fromMilliseconds; - fromNanoseconds = base.fromNanoseconds; - adjust = base.adjust; - } - - @Override - protected JsonDeserializer withDateFormat(DateTimeFormatter dtf) { - if (dtf == _formatter) { - return this; - } - return new CustomInstantDeserializer(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; - } - } -} diff --git a/samples/client/petstore/java/resteasy/src/main/java/io/swagger/client/api/FakeApi.java b/samples/client/petstore/java/resteasy/src/main/java/io/swagger/client/api/FakeApi.java index 8110632ad6..884dd912f6 100644 --- a/samples/client/petstore/java/resteasy/src/main/java/io/swagger/client/api/FakeApi.java +++ b/samples/client/petstore/java/resteasy/src/main/java/io/swagger/client/api/FakeApi.java @@ -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 diff --git a/samples/client/petstore/java/resteasy/src/main/java/io/swagger/client/model/FormatTest.java b/samples/client/petstore/java/resteasy/src/main/java/io/swagger/client/model/FormatTest.java index 3897095d84..c2aa5f35fe 100644 --- a/samples/client/petstore/java/resteasy/src/main/java/io/swagger/client/model/FormatTest.java +++ b/samples/client/petstore/java/resteasy/src/main/java/io/swagger/client/model/FormatTest.java @@ -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; } diff --git a/samples/client/petstore/java/resteasy/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java b/samples/client/petstore/java/resteasy/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java index 229669da93..9cd0ca678b 100644 --- a/samples/client/petstore/java/resteasy/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java +++ b/samples/client/petstore/java/resteasy/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java @@ -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 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; } diff --git a/samples/client/petstore/java/resteasy/src/main/java/io/swagger/client/model/Order.java b/samples/client/petstore/java/resteasy/src/main/java/io/swagger/client/model/Order.java index 2edfd83b31..d08d27721a 100644 --- a/samples/client/petstore/java/resteasy/src/main/java/io/swagger/client/model/Order.java +++ b/samples/client/petstore/java/resteasy/src/main/java/io/swagger/client/model/Order.java @@ -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; } diff --git a/samples/client/petstore/java/resttemplate/.swagger-codegen/VERSION b/samples/client/petstore/java/resttemplate/.swagger-codegen/VERSION index f9f7450d13..7fea99011a 100644 --- a/samples/client/petstore/java/resttemplate/.swagger-codegen/VERSION +++ b/samples/client/petstore/java/resttemplate/.swagger-codegen/VERSION @@ -1 +1 @@ -2.3.0-SNAPSHOT \ No newline at end of file +2.2.3-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/java/resttemplate/build.gradle b/samples/client/petstore/java/resttemplate/build.gradle index 4ad1f2e122..eeb852d309 100644 --- a/samples/client/petstore/java/resttemplate/build.gradle +++ b/samples/client/petstore/java/resttemplate/build.gradle @@ -99,7 +99,6 @@ ext { spring_web_version = "4.3.9.RELEASE" jodatime_version = "2.9.9" junit_version = "4.12" - jackson_threeten_version = "2.6.4" } dependencies { @@ -109,6 +108,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_threeten_version" + compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:$jackson_version" + compile "joda-time:joda-time:$jodatime_version" testCompile "junit:junit:$junit_version" } diff --git a/samples/client/petstore/java/resttemplate/docs/FakeApi.md b/samples/client/petstore/java/resttemplate/docs/FakeApi.md index 79aed327d1..5a061d3e6b 100644 --- a/samples/client/petstore/java/resttemplate/docs/FakeApi.md +++ b/samples/client/petstore/java/resttemplate/docs/FakeApi.md @@ -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] diff --git a/samples/client/petstore/java/resttemplate/docs/FormatTest.md b/samples/client/petstore/java/resttemplate/docs/FormatTest.md index c7a3acb3cb..06bed41723 100644 --- a/samples/client/petstore/java/resttemplate/docs/FormatTest.md +++ b/samples/client/petstore/java/resttemplate/docs/FormatTest.md @@ -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** | | diff --git a/samples/client/petstore/java/resttemplate/docs/MixedPropertiesAndAdditionalPropertiesClass.md b/samples/client/petstore/java/resttemplate/docs/MixedPropertiesAndAdditionalPropertiesClass.md index b12e2cd70e..349afef35a 100644 --- a/samples/client/petstore/java/resttemplate/docs/MixedPropertiesAndAdditionalPropertiesClass.md +++ b/samples/client/petstore/java/resttemplate/docs/MixedPropertiesAndAdditionalPropertiesClass.md @@ -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] diff --git a/samples/client/petstore/java/resttemplate/docs/Order.md b/samples/client/petstore/java/resttemplate/docs/Order.md index 268c617d1f..a1089f5384 100644 --- a/samples/client/petstore/java/resttemplate/docs/Order.md +++ b/samples/client/petstore/java/resttemplate/docs/Order.md @@ -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] diff --git a/samples/client/petstore/java/resttemplate/pom.xml b/samples/client/petstore/java/resttemplate/pom.xml index 0eb7db54a1..01059b5fcb 100644 --- a/samples/client/petstore/java/resttemplate/pom.xml +++ b/samples/client/petstore/java/resttemplate/pom.xml @@ -213,9 +213,14 @@ ${jackson-version} - com.github.joschi.jackson - jackson-datatype-threetenbp - ${jackson-threetenbp-version} + com.fasterxml.jackson.datatype + jackson-datatype-joda + ${jackson-version} + + + joda-time + joda-time + ${jodatime-version} @@ -231,7 +236,7 @@ 1.5.15 4.3.9.RELEASE 2.8.9 - 2.6.4 + 2.9.9 1.0.0 4.12 diff --git a/samples/client/petstore/java/resttemplate/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/resttemplate/src/main/java/io/swagger/client/ApiClient.java index d8d84aedfb..04565c0efe 100644 --- a/samples/client/petstore/java/resttemplate/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/resttemplate/src/main/java/io/swagger/client/ApiClient.java @@ -24,11 +24,6 @@ import org.springframework.util.StringUtils; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; -import org.threeten.bp.*; -import com.fasterxml.jackson.datatype.threetenbp.ThreeTenModule; -import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; -import com.fasterxml.jackson.databind.ObjectMapper; import java.io.BufferedReader; import java.io.IOException; @@ -308,12 +303,6 @@ public class ApiClient { */ public ApiClient setDateFormat(DateFormat dateFormat) { this.dateFormat = dateFormat; - for(HttpMessageConverter converter:restTemplate.getMessageConverters()){ - if(converter instanceof AbstractJackson2HttpMessageConverter){ - ObjectMapper mapper = ((AbstractJackson2HttpMessageConverter)converter).getObjectMapper(); - mapper.setDateFormat(dateFormat); - } - } return this; } @@ -562,16 +551,6 @@ public class ApiClient { */ protected RestTemplate buildRestTemplate() { RestTemplate restTemplate = new RestTemplate(); - for(HttpMessageConverter converter:restTemplate.getMessageConverters()){ - if(converter instanceof AbstractJackson2HttpMessageConverter){ - ObjectMapper mapper = ((AbstractJackson2HttpMessageConverter)converter).getObjectMapper(); - 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); - } - } // This allows us to read the response more than once - Necessary for debugging. restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(restTemplate.getRequestFactory())); return restTemplate; diff --git a/samples/client/petstore/java/resttemplate/src/main/java/io/swagger/client/CustomInstantDeserializer.java b/samples/client/petstore/java/resttemplate/src/main/java/io/swagger/client/CustomInstantDeserializer.java deleted file mode 100644 index 5ed8ba446e..0000000000 --- a/samples/client/petstore/java/resttemplate/src/main/java/io/swagger/client/CustomInstantDeserializer.java +++ /dev/null @@ -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 - extends ThreeTenDateTimeDeserializerBase { - private static final long serialVersionUID = 1L; - - public static final CustomInstantDeserializer INSTANT = new CustomInstantDeserializer( - Instant.class, DateTimeFormatter.ISO_INSTANT, - new Function() { - @Override - public Instant apply(TemporalAccessor temporalAccessor) { - return Instant.from(temporalAccessor); - } - }, - new Function() { - @Override - public Instant apply(FromIntegerArguments a) { - return Instant.ofEpochMilli(a.value); - } - }, - new Function() { - @Override - public Instant apply(FromDecimalArguments a) { - return Instant.ofEpochSecond(a.integer, a.fraction); - } - }, - null - ); - - public static final CustomInstantDeserializer OFFSET_DATE_TIME = new CustomInstantDeserializer( - OffsetDateTime.class, DateTimeFormatter.ISO_OFFSET_DATE_TIME, - new Function() { - @Override - public OffsetDateTime apply(TemporalAccessor temporalAccessor) { - return OffsetDateTime.from(temporalAccessor); - } - }, - new Function() { - @Override - public OffsetDateTime apply(FromIntegerArguments a) { - return OffsetDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId); - } - }, - new Function() { - @Override - public OffsetDateTime apply(FromDecimalArguments a) { - return OffsetDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId); - } - }, - new BiFunction() { - @Override - public OffsetDateTime apply(OffsetDateTime d, ZoneId z) { - return d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime())); - } - } - ); - - public static final CustomInstantDeserializer ZONED_DATE_TIME = new CustomInstantDeserializer( - ZonedDateTime.class, DateTimeFormatter.ISO_ZONED_DATE_TIME, - new Function() { - @Override - public ZonedDateTime apply(TemporalAccessor temporalAccessor) { - return ZonedDateTime.from(temporalAccessor); - } - }, - new Function() { - @Override - public ZonedDateTime apply(FromIntegerArguments a) { - return ZonedDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId); - } - }, - new Function() { - @Override - public ZonedDateTime apply(FromDecimalArguments a) { - return ZonedDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId); - } - }, - new BiFunction() { - @Override - public ZonedDateTime apply(ZonedDateTime zonedDateTime, ZoneId zoneId) { - return zonedDateTime.withZoneSameInstant(zoneId); - } - } - ); - - protected final Function fromMilliseconds; - - protected final Function fromNanoseconds; - - protected final Function parsedToValue; - - protected final BiFunction adjust; - - protected CustomInstantDeserializer(Class supportedType, - DateTimeFormatter parser, - Function parsedToValue, - Function fromMilliseconds, - Function fromNanoseconds, - BiFunction adjust) { - super(supportedType, parser); - this.parsedToValue = parsedToValue; - this.fromMilliseconds = fromMilliseconds; - this.fromNanoseconds = fromNanoseconds; - this.adjust = adjust == null ? new BiFunction() { - @Override - public T apply(T t, ZoneId zoneId) { - return t; - } - } : adjust; - } - - @SuppressWarnings("unchecked") - protected CustomInstantDeserializer(CustomInstantDeserializer base, DateTimeFormatter f) { - super((Class) base.handledType(), f); - parsedToValue = base.parsedToValue; - fromMilliseconds = base.fromMilliseconds; - fromNanoseconds = base.fromNanoseconds; - adjust = base.adjust; - } - - @Override - protected JsonDeserializer withDateFormat(DateTimeFormatter dtf) { - if (dtf == _formatter) { - return this; - } - return new CustomInstantDeserializer(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; - } - } -} diff --git a/samples/client/petstore/java/resttemplate/src/main/java/io/swagger/client/api/FakeApi.java b/samples/client/petstore/java/resttemplate/src/main/java/io/swagger/client/api/FakeApi.java index 8393e7097f..22320fa7f9 100644 --- a/samples/client/petstore/java/resttemplate/src/main/java/io/swagger/client/api/FakeApi.java +++ b/samples/client/petstore/java/resttemplate/src/main/java/io/swagger/client/api/FakeApi.java @@ -4,8 +4,8 @@ import io.swagger.client.ApiClient; 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; @@ -214,7 +214,7 @@ public class FakeApi { * @param paramCallback None * @throws RestClientException if an error occurs while attempting to invoke the API */ - 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 RestClientException { + 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 RestClientException { Object postBody = null; // verify the required parameter 'number' is set diff --git a/samples/client/petstore/java/resttemplate/src/main/java/io/swagger/client/model/FormatTest.java b/samples/client/petstore/java/resttemplate/src/main/java/io/swagger/client/model/FormatTest.java index 3897095d84..c2aa5f35fe 100644 --- a/samples/client/petstore/java/resttemplate/src/main/java/io/swagger/client/model/FormatTest.java +++ b/samples/client/petstore/java/resttemplate/src/main/java/io/swagger/client/model/FormatTest.java @@ -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; } diff --git a/samples/client/petstore/java/resttemplate/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java b/samples/client/petstore/java/resttemplate/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java index 229669da93..9cd0ca678b 100644 --- a/samples/client/petstore/java/resttemplate/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java +++ b/samples/client/petstore/java/resttemplate/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java @@ -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 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; } diff --git a/samples/client/petstore/java/resttemplate/src/main/java/io/swagger/client/model/Order.java b/samples/client/petstore/java/resttemplate/src/main/java/io/swagger/client/model/Order.java index 2edfd83b31..d08d27721a 100644 --- a/samples/client/petstore/java/resttemplate/src/main/java/io/swagger/client/model/Order.java +++ b/samples/client/petstore/java/resttemplate/src/main/java/io/swagger/client/model/Order.java @@ -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; } diff --git a/samples/client/petstore/java/retrofit/.swagger-codegen/VERSION b/samples/client/petstore/java/retrofit/.swagger-codegen/VERSION index f9f7450d13..7fea99011a 100644 --- a/samples/client/petstore/java/retrofit/.swagger-codegen/VERSION +++ b/samples/client/petstore/java/retrofit/.swagger-codegen/VERSION @@ -1 +1 @@ -2.3.0-SNAPSHOT \ No newline at end of file +2.2.3-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/java/retrofit2-play24/.swagger-codegen/VERSION b/samples/client/petstore/java/retrofit2-play24/.swagger-codegen/VERSION index f9f7450d13..7fea99011a 100644 --- a/samples/client/petstore/java/retrofit2-play24/.swagger-codegen/VERSION +++ b/samples/client/petstore/java/retrofit2-play24/.swagger-codegen/VERSION @@ -1 +1 @@ -2.3.0-SNAPSHOT \ No newline at end of file +2.2.3-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/java/retrofit2-play24/build.gradle b/samples/client/petstore/java/retrofit2-play24/build.gradle index 99773a8c88..660aa9a74f 100644 --- a/samples/client/petstore/java/retrofit2-play24/build.gradle +++ b/samples/client/petstore/java/retrofit2-play24/build.gradle @@ -100,7 +100,7 @@ ext { play_version = "2.4.11" swagger_annotations_version = "1.5.15" junit_version = "4.12" - threetenbp_version = "1.3.5" + jodatime_version = "2.9.9" } dependencies { @@ -109,7 +109,7 @@ dependencies { compile "com.squareup.retrofit2:converter-gson:$retrofit_version" compile "io.swagger:swagger-annotations:$swagger_annotations_version" compile "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version" - compile "org.threeten:threetenbp:$threetenbp_version" + compile "joda-time:joda-time:$jodatime_version" compile "com.typesafe.play:play-java-ws_2.11:$play_version" compile "com.squareup.retrofit2:converter-jackson:$retrofit_version" compile "com.fasterxml.jackson.core:jackson-core:$jackson_version" diff --git a/samples/client/petstore/java/retrofit2-play24/build.sbt b/samples/client/petstore/java/retrofit2-play24/build.sbt index 555352f5fe..60a3d4c78e 100644 --- a/samples/client/petstore/java/retrofit2-play24/build.sbt +++ b/samples/client/petstore/java/retrofit2-play24/build.sbt @@ -19,7 +19,7 @@ lazy val root = (project in file(".")). "com.fasterxml.jackson.core" % "jackson-databind" % "2.8.9" % "compile", "io.swagger" % "swagger-annotations" % "1.5.15" % "compile", "org.apache.oltu.oauth2" % "org.apache.oltu.oauth2.client" % "1.0.1" % "compile", - "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.11" % "test" ) diff --git a/samples/client/petstore/java/retrofit2-play24/docs/FakeApi.md b/samples/client/petstore/java/retrofit2-play24/docs/FakeApi.md index 43d5c4c20c..1b53ccee14 100644 --- a/samples/client/petstore/java/retrofit2-play24/docs/FakeApi.md +++ b/samples/client/petstore/java/retrofit2-play24/docs/FakeApi.md @@ -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 { @@ -302,7 +302,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] diff --git a/samples/client/petstore/java/retrofit2-play24/docs/FormatTest.md b/samples/client/petstore/java/retrofit2-play24/docs/FormatTest.md index c7a3acb3cb..06bed41723 100644 --- a/samples/client/petstore/java/retrofit2-play24/docs/FormatTest.md +++ b/samples/client/petstore/java/retrofit2-play24/docs/FormatTest.md @@ -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** | | diff --git a/samples/client/petstore/java/retrofit2-play24/docs/MixedPropertiesAndAdditionalPropertiesClass.md b/samples/client/petstore/java/retrofit2-play24/docs/MixedPropertiesAndAdditionalPropertiesClass.md index b12e2cd70e..349afef35a 100644 --- a/samples/client/petstore/java/retrofit2-play24/docs/MixedPropertiesAndAdditionalPropertiesClass.md +++ b/samples/client/petstore/java/retrofit2-play24/docs/MixedPropertiesAndAdditionalPropertiesClass.md @@ -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] diff --git a/samples/client/petstore/java/retrofit2-play24/docs/Order.md b/samples/client/petstore/java/retrofit2-play24/docs/Order.md index 268c617d1f..a1089f5384 100644 --- a/samples/client/petstore/java/retrofit2-play24/docs/Order.md +++ b/samples/client/petstore/java/retrofit2-play24/docs/Order.md @@ -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] diff --git a/samples/client/petstore/java/retrofit2-play24/pom.xml b/samples/client/petstore/java/retrofit2-play24/pom.xml index b80b50ef5b..f711d86178 100644 --- a/samples/client/petstore/java/retrofit2-play24/pom.xml +++ b/samples/client/petstore/java/retrofit2-play24/pom.xml @@ -195,9 +195,9 @@ ${oltu-version} - org.threeten - threetenbp - ${threetenbp-version} + joda-time + joda-time + ${jodatime-version} @@ -250,7 +250,7 @@ 2.8.9 2.4.11 2.3.0 - 1.3.5 + 2.9.9 1.0.1 4.12 diff --git a/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/CustomInstantDeserializer.java b/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/CustomInstantDeserializer.java deleted file mode 100644 index 5ed8ba446e..0000000000 --- a/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/CustomInstantDeserializer.java +++ /dev/null @@ -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 - extends ThreeTenDateTimeDeserializerBase { - private static final long serialVersionUID = 1L; - - public static final CustomInstantDeserializer INSTANT = new CustomInstantDeserializer( - Instant.class, DateTimeFormatter.ISO_INSTANT, - new Function() { - @Override - public Instant apply(TemporalAccessor temporalAccessor) { - return Instant.from(temporalAccessor); - } - }, - new Function() { - @Override - public Instant apply(FromIntegerArguments a) { - return Instant.ofEpochMilli(a.value); - } - }, - new Function() { - @Override - public Instant apply(FromDecimalArguments a) { - return Instant.ofEpochSecond(a.integer, a.fraction); - } - }, - null - ); - - public static final CustomInstantDeserializer OFFSET_DATE_TIME = new CustomInstantDeserializer( - OffsetDateTime.class, DateTimeFormatter.ISO_OFFSET_DATE_TIME, - new Function() { - @Override - public OffsetDateTime apply(TemporalAccessor temporalAccessor) { - return OffsetDateTime.from(temporalAccessor); - } - }, - new Function() { - @Override - public OffsetDateTime apply(FromIntegerArguments a) { - return OffsetDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId); - } - }, - new Function() { - @Override - public OffsetDateTime apply(FromDecimalArguments a) { - return OffsetDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId); - } - }, - new BiFunction() { - @Override - public OffsetDateTime apply(OffsetDateTime d, ZoneId z) { - return d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime())); - } - } - ); - - public static final CustomInstantDeserializer ZONED_DATE_TIME = new CustomInstantDeserializer( - ZonedDateTime.class, DateTimeFormatter.ISO_ZONED_DATE_TIME, - new Function() { - @Override - public ZonedDateTime apply(TemporalAccessor temporalAccessor) { - return ZonedDateTime.from(temporalAccessor); - } - }, - new Function() { - @Override - public ZonedDateTime apply(FromIntegerArguments a) { - return ZonedDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId); - } - }, - new Function() { - @Override - public ZonedDateTime apply(FromDecimalArguments a) { - return ZonedDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId); - } - }, - new BiFunction() { - @Override - public ZonedDateTime apply(ZonedDateTime zonedDateTime, ZoneId zoneId) { - return zonedDateTime.withZoneSameInstant(zoneId); - } - } - ); - - protected final Function fromMilliseconds; - - protected final Function fromNanoseconds; - - protected final Function parsedToValue; - - protected final BiFunction adjust; - - protected CustomInstantDeserializer(Class supportedType, - DateTimeFormatter parser, - Function parsedToValue, - Function fromMilliseconds, - Function fromNanoseconds, - BiFunction adjust) { - super(supportedType, parser); - this.parsedToValue = parsedToValue; - this.fromMilliseconds = fromMilliseconds; - this.fromNanoseconds = fromNanoseconds; - this.adjust = adjust == null ? new BiFunction() { - @Override - public T apply(T t, ZoneId zoneId) { - return t; - } - } : adjust; - } - - @SuppressWarnings("unchecked") - protected CustomInstantDeserializer(CustomInstantDeserializer base, DateTimeFormatter f) { - super((Class) base.handledType(), f); - parsedToValue = base.parsedToValue; - fromMilliseconds = base.fromMilliseconds; - fromNanoseconds = base.fromNanoseconds; - adjust = base.adjust; - } - - @Override - protected JsonDeserializer withDateFormat(DateTimeFormatter dtf) { - if (dtf == _formatter) { - return this; - } - return new CustomInstantDeserializer(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; - } - } -} diff --git a/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/JSON.java b/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/JSON.java deleted file mode 100644 index 590495331b..0000000000 --- a/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/JSON.java +++ /dev/null @@ -1,289 +0,0 @@ -/* - * Swagger Petstore - * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ - * - * OpenAPI spec version: 1.0.0 - * Contact: apiteam@swagger.io - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ - - -package io.swagger.client; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonParseException; -import com.google.gson.TypeAdapter; -import com.google.gson.internal.bind.util.ISO8601Utils; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; -import org.threeten.bp.LocalDate; -import org.threeten.bp.OffsetDateTime; -import org.threeten.bp.format.DateTimeFormatter; - -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; - -public class JSON { - private Gson gson; - private DateTypeAdapter dateTypeAdapter = new DateTypeAdapter(); - private SqlDateTypeAdapter sqlDateTypeAdapter = new SqlDateTypeAdapter(); - private OffsetDateTimeTypeAdapter offsetDateTimeTypeAdapter = new OffsetDateTimeTypeAdapter(); - 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(LocalDate.class, localDateTypeAdapter) - .create(); - } - - /** - * Get Gson. - * - * @return Gson - */ - public Gson getGson() { - return gson; - } - - /** - * Set Gson. - * - * @param gson Gson - * @return JSON - */ - public JSON setGson(Gson gson) { - this.gson = gson; - return this; - } - - /** - * Gson TypeAdapter for JSR310 OffsetDateTime type - */ - public static class OffsetDateTimeTypeAdapter extends TypeAdapter { - - private DateTimeFormatter formatter; - - public OffsetDateTimeTypeAdapter() { - this(DateTimeFormatter.ISO_OFFSET_DATE_TIME); - } - - public OffsetDateTimeTypeAdapter(DateTimeFormatter formatter) { - this.formatter = formatter; - } - - public void setFormat(DateTimeFormatter dateFormat) { - this.formatter = dateFormat; - } - - @Override - public void write(JsonWriter out, OffsetDateTime date) throws IOException { - if (date == null) { - out.nullValue(); - } else { - out.value(formatter.format(date)); - } - } - - @Override - public OffsetDateTime 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); - } - } - } - - /** - * Gson TypeAdapter for JSR310 LocalDate type - */ - public class LocalDateTypeAdapter extends TypeAdapter { - - private DateTimeFormatter formatter; - - public LocalDateTypeAdapter() { - this(DateTimeFormatter.ISO_LOCAL_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.format(date)); - } - } - - @Override - public LocalDate read(JsonReader in) throws IOException { - switch (in.peek()) { - case NULL: - in.nextNull(); - return null; - default: - String date = in.nextString(); - return LocalDate.parse(date, formatter); - } - } - } - - public JSON setOffsetDateTimeFormat(DateTimeFormatter dateFormat) { - offsetDateTimeTypeAdapter.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 { - - 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 { - - 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; - } - -} diff --git a/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/api/FakeApi.java b/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/api/FakeApi.java index f264d32ba9..ddfd251eb1 100644 --- a/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/api/FakeApi.java +++ b/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/api/FakeApi.java @@ -2,6 +2,8 @@ package io.swagger.client.api; import io.swagger.client.CollectionFormats.*; + + import retrofit2.Call; import retrofit2.http.*; @@ -9,8 +11,8 @@ import okhttp3.RequestBody; 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; @@ -102,7 +104,7 @@ public interface FakeApi { @retrofit2.http.FormUrlEncoded @POST("fake") F.Promise> testEndpointParameters( - @retrofit2.http.Field("number") BigDecimal number, @retrofit2.http.Field("double") Double _double, @retrofit2.http.Field("pattern_without_delimiter") String patternWithoutDelimiter, @retrofit2.http.Field("byte") byte[] _byte, @retrofit2.http.Field("integer") Integer integer, @retrofit2.http.Field("int32") Integer int32, @retrofit2.http.Field("int64") Long int64, @retrofit2.http.Field("float") Float _float, @retrofit2.http.Field("string") String string, @retrofit2.http.Field("binary") byte[] binary, @retrofit2.http.Field("date") LocalDate date, @retrofit2.http.Field("dateTime") OffsetDateTime dateTime, @retrofit2.http.Field("password") String password, @retrofit2.http.Field("callback") String paramCallback + @retrofit2.http.Field("number") BigDecimal number, @retrofit2.http.Field("double") Double _double, @retrofit2.http.Field("pattern_without_delimiter") String patternWithoutDelimiter, @retrofit2.http.Field("byte") byte[] _byte, @retrofit2.http.Field("integer") Integer integer, @retrofit2.http.Field("int32") Integer int32, @retrofit2.http.Field("int64") Long int64, @retrofit2.http.Field("float") Float _float, @retrofit2.http.Field("string") String string, @retrofit2.http.Field("binary") byte[] binary, @retrofit2.http.Field("date") LocalDate date, @retrofit2.http.Field("dateTime") DateTime dateTime, @retrofit2.http.Field("password") String password, @retrofit2.http.Field("callback") String paramCallback ); /** diff --git a/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/api/FakeClassnameTags123Api.java b/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/api/FakeClassnameTags123Api.java index feb5c347ef..1aef86538f 100644 --- a/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/api/FakeClassnameTags123Api.java +++ b/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/api/FakeClassnameTags123Api.java @@ -2,6 +2,8 @@ package io.swagger.client.api; import io.swagger.client.CollectionFormats.*; + + import retrofit2.Call; import retrofit2.http.*; diff --git a/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/api/PetApi.java b/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/api/PetApi.java index 343eeb1e78..8f841a8f1e 100644 --- a/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/api/PetApi.java +++ b/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/api/PetApi.java @@ -2,6 +2,8 @@ package io.swagger.client.api; import io.swagger.client.CollectionFormats.*; + + import retrofit2.Call; import retrofit2.http.*; diff --git a/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/api/StoreApi.java b/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/api/StoreApi.java index a32bbbb9e8..3cfefc29b9 100644 --- a/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/api/StoreApi.java +++ b/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/api/StoreApi.java @@ -2,6 +2,8 @@ package io.swagger.client.api; import io.swagger.client.CollectionFormats.*; + + import retrofit2.Call; import retrofit2.http.*; diff --git a/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/api/UserApi.java b/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/api/UserApi.java index cea84a9ab7..9b55346300 100644 --- a/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/api/UserApi.java +++ b/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/api/UserApi.java @@ -2,6 +2,8 @@ package io.swagger.client.api; import io.swagger.client.CollectionFormats.*; + + import retrofit2.Call; import retrofit2.http.*; diff --git a/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/model/FormatTest.java b/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/model/FormatTest.java index b5ba3dfb4c..feab1d429d 100644 --- a/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/model/FormatTest.java +++ b/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/model/FormatTest.java @@ -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; import javax.validation.constraints.*; import javax.validation.Valid; @@ -62,7 +62,7 @@ public class FormatTest { private LocalDate date = null; @JsonProperty("dateTime") - private OffsetDateTime dateTime = null; + private DateTime dateTime = null; @JsonProperty("uuid") private UUID uuid = null; @@ -265,7 +265,7 @@ public class FormatTest { this.date = date; } - public FormatTest dateTime(OffsetDateTime dateTime) { + public FormatTest dateTime(DateTime dateTime) { this.dateTime = dateTime; return this; } @@ -276,11 +276,11 @@ public class FormatTest { **/ @Valid @ApiModelProperty(value = "") - public OffsetDateTime getDateTime() { + public DateTime getDateTime() { return dateTime; } - public void setDateTime(OffsetDateTime dateTime) { + public void setDateTime(DateTime dateTime) { this.dateTime = dateTime; } diff --git a/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java b/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java index d4d344023c..584389c697 100644 --- a/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java +++ b/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java @@ -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; import javax.validation.constraints.*; import javax.validation.Valid; @@ -37,7 +37,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass { private UUID uuid = null; @JsonProperty("dateTime") - private OffsetDateTime dateTime = null; + private DateTime dateTime = null; @JsonProperty("map") private Map map = null; @@ -61,7 +61,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass { this.uuid = uuid; } - public MixedPropertiesAndAdditionalPropertiesClass dateTime(OffsetDateTime dateTime) { + public MixedPropertiesAndAdditionalPropertiesClass dateTime(DateTime dateTime) { this.dateTime = dateTime; return this; } @@ -72,11 +72,11 @@ public class MixedPropertiesAndAdditionalPropertiesClass { **/ @Valid @ApiModelProperty(value = "") - public OffsetDateTime getDateTime() { + public DateTime getDateTime() { return dateTime; } - public void setDateTime(OffsetDateTime dateTime) { + public void setDateTime(DateTime dateTime) { this.dateTime = dateTime; } diff --git a/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/model/Order.java b/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/model/Order.java index 275172b86f..fef07f4b9e 100644 --- a/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/model/Order.java +++ b/samples/client/petstore/java/retrofit2-play24/src/main/java/io/swagger/client/model/Order.java @@ -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; import javax.validation.constraints.*; import javax.validation.Valid; @@ -38,7 +38,7 @@ public class Order { private Integer quantity = null; @JsonProperty("shipDate") - private OffsetDateTime shipDate = null; + private DateTime shipDate = null; /** * Order Status @@ -137,7 +137,7 @@ public class Order { this.quantity = quantity; } - public Order shipDate(OffsetDateTime shipDate) { + public Order shipDate(DateTime shipDate) { this.shipDate = shipDate; return this; } @@ -148,11 +148,11 @@ public class Order { **/ @Valid @ApiModelProperty(value = "") - public OffsetDateTime getShipDate() { + public DateTime getShipDate() { return shipDate; } - public void setShipDate(OffsetDateTime shipDate) { + public void setShipDate(DateTime shipDate) { this.shipDate = shipDate; } diff --git a/samples/client/petstore/java/retrofit2/.swagger-codegen/VERSION b/samples/client/petstore/java/retrofit2/.swagger-codegen/VERSION index f9f7450d13..7fea99011a 100644 --- a/samples/client/petstore/java/retrofit2/.swagger-codegen/VERSION +++ b/samples/client/petstore/java/retrofit2/.swagger-codegen/VERSION @@ -1 +1 @@ -2.3.0-SNAPSHOT \ No newline at end of file +2.2.3-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/java/retrofit2/build.gradle b/samples/client/petstore/java/retrofit2/build.gradle index 9c7f627e48..32fa566abd 100644 --- a/samples/client/petstore/java/retrofit2/build.gradle +++ b/samples/client/petstore/java/retrofit2/build.gradle @@ -98,7 +98,7 @@ ext { retrofit_version = "2.3.0" swagger_annotations_version = "1.5.15" junit_version = "4.12" - threetenbp_version = "1.3.5" + jodatime_version = "2.9.9" } dependencies { @@ -107,7 +107,7 @@ dependencies { compile "com.squareup.retrofit2:converter-gson:$retrofit_version" compile "io.swagger:swagger-annotations:$swagger_annotations_version" compile "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version" - compile "org.threeten:threetenbp:$threetenbp_version" + compile "joda-time:joda-time:$jodatime_version" testCompile "junit:junit:$junit_version" } diff --git a/samples/client/petstore/java/retrofit2/build.sbt b/samples/client/petstore/java/retrofit2/build.sbt index de55c31451..84cf487258 100644 --- a/samples/client/petstore/java/retrofit2/build.sbt +++ b/samples/client/petstore/java/retrofit2/build.sbt @@ -14,7 +14,7 @@ lazy val root = (project in file(".")). "com.squareup.retrofit2" % "converter-gson" % "2.3.0" % "compile", "io.swagger" % "swagger-annotations" % "1.5.15" % "compile", "org.apache.oltu.oauth2" % "org.apache.oltu.oauth2.client" % "1.0.1" % "compile", - "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.11" % "test" ) diff --git a/samples/client/petstore/java/retrofit2/docs/FakeApi.md b/samples/client/petstore/java/retrofit2/docs/FakeApi.md index 43d5c4c20c..1b53ccee14 100644 --- a/samples/client/petstore/java/retrofit2/docs/FakeApi.md +++ b/samples/client/petstore/java/retrofit2/docs/FakeApi.md @@ -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 { @@ -302,7 +302,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] diff --git a/samples/client/petstore/java/retrofit2/docs/FormatTest.md b/samples/client/petstore/java/retrofit2/docs/FormatTest.md index c7a3acb3cb..06bed41723 100644 --- a/samples/client/petstore/java/retrofit2/docs/FormatTest.md +++ b/samples/client/petstore/java/retrofit2/docs/FormatTest.md @@ -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** | | diff --git a/samples/client/petstore/java/retrofit2/docs/MixedPropertiesAndAdditionalPropertiesClass.md b/samples/client/petstore/java/retrofit2/docs/MixedPropertiesAndAdditionalPropertiesClass.md index b12e2cd70e..349afef35a 100644 --- a/samples/client/petstore/java/retrofit2/docs/MixedPropertiesAndAdditionalPropertiesClass.md +++ b/samples/client/petstore/java/retrofit2/docs/MixedPropertiesAndAdditionalPropertiesClass.md @@ -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] diff --git a/samples/client/petstore/java/retrofit2/docs/Order.md b/samples/client/petstore/java/retrofit2/docs/Order.md index 268c617d1f..a1089f5384 100644 --- a/samples/client/petstore/java/retrofit2/docs/Order.md +++ b/samples/client/petstore/java/retrofit2/docs/Order.md @@ -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] diff --git a/samples/client/petstore/java/retrofit2/pom.xml b/samples/client/petstore/java/retrofit2/pom.xml index c6a92971af..c9a8b343c8 100644 --- a/samples/client/petstore/java/retrofit2/pom.xml +++ b/samples/client/petstore/java/retrofit2/pom.xml @@ -195,9 +195,9 @@ ${oltu-version} - org.threeten - threetenbp - ${threetenbp-version} + joda-time + joda-time + ${jodatime-version} @@ -217,7 +217,7 @@ ${java.version} 1.5.15 2.3.0 - 1.3.5 + 2.9.9 1.0.1 4.12 diff --git a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/ApiClient.java index ccd9842807..8c9a5ed61e 100644 --- a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/ApiClient.java @@ -8,7 +8,7 @@ import okhttp3.RequestBody; import okhttp3.ResponseBody; import org.apache.oltu.oauth2.client.request.OAuthClientRequest.AuthenticationRequestBuilder; import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder; -import org.threeten.bp.format.DateTimeFormatter; +import org.joda.time.format.DateTimeFormatter; import retrofit2.Converter; import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; @@ -134,8 +134,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; } diff --git a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/JSON.java b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/JSON.java deleted file mode 100644 index 590495331b..0000000000 --- a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/JSON.java +++ /dev/null @@ -1,289 +0,0 @@ -/* - * Swagger Petstore - * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ - * - * OpenAPI spec version: 1.0.0 - * Contact: apiteam@swagger.io - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ - - -package io.swagger.client; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonParseException; -import com.google.gson.TypeAdapter; -import com.google.gson.internal.bind.util.ISO8601Utils; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; -import org.threeten.bp.LocalDate; -import org.threeten.bp.OffsetDateTime; -import org.threeten.bp.format.DateTimeFormatter; - -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; - -public class JSON { - private Gson gson; - private DateTypeAdapter dateTypeAdapter = new DateTypeAdapter(); - private SqlDateTypeAdapter sqlDateTypeAdapter = new SqlDateTypeAdapter(); - private OffsetDateTimeTypeAdapter offsetDateTimeTypeAdapter = new OffsetDateTimeTypeAdapter(); - 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(LocalDate.class, localDateTypeAdapter) - .create(); - } - - /** - * Get Gson. - * - * @return Gson - */ - public Gson getGson() { - return gson; - } - - /** - * Set Gson. - * - * @param gson Gson - * @return JSON - */ - public JSON setGson(Gson gson) { - this.gson = gson; - return this; - } - - /** - * Gson TypeAdapter for JSR310 OffsetDateTime type - */ - public static class OffsetDateTimeTypeAdapter extends TypeAdapter { - - private DateTimeFormatter formatter; - - public OffsetDateTimeTypeAdapter() { - this(DateTimeFormatter.ISO_OFFSET_DATE_TIME); - } - - public OffsetDateTimeTypeAdapter(DateTimeFormatter formatter) { - this.formatter = formatter; - } - - public void setFormat(DateTimeFormatter dateFormat) { - this.formatter = dateFormat; - } - - @Override - public void write(JsonWriter out, OffsetDateTime date) throws IOException { - if (date == null) { - out.nullValue(); - } else { - out.value(formatter.format(date)); - } - } - - @Override - public OffsetDateTime 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); - } - } - } - - /** - * Gson TypeAdapter for JSR310 LocalDate type - */ - public class LocalDateTypeAdapter extends TypeAdapter { - - private DateTimeFormatter formatter; - - public LocalDateTypeAdapter() { - this(DateTimeFormatter.ISO_LOCAL_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.format(date)); - } - } - - @Override - public LocalDate read(JsonReader in) throws IOException { - switch (in.peek()) { - case NULL: - in.nextNull(); - return null; - default: - String date = in.nextString(); - return LocalDate.parse(date, formatter); - } - } - } - - public JSON setOffsetDateTimeFormat(DateTimeFormatter dateFormat) { - offsetDateTimeTypeAdapter.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 { - - 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 { - - 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; - } - -} diff --git a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/api/FakeApi.java b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/api/FakeApi.java index 5eb2fb0d8b..9a87081156 100644 --- a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/api/FakeApi.java +++ b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/api/FakeApi.java @@ -9,8 +9,8 @@ import okhttp3.RequestBody; 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; @@ -100,7 +100,7 @@ public interface FakeApi { @retrofit2.http.FormUrlEncoded @POST("fake") Call testEndpointParameters( - @retrofit2.http.Field("number") BigDecimal number, @retrofit2.http.Field("double") Double _double, @retrofit2.http.Field("pattern_without_delimiter") String patternWithoutDelimiter, @retrofit2.http.Field("byte") byte[] _byte, @retrofit2.http.Field("integer") Integer integer, @retrofit2.http.Field("int32") Integer int32, @retrofit2.http.Field("int64") Long int64, @retrofit2.http.Field("float") Float _float, @retrofit2.http.Field("string") String string, @retrofit2.http.Field("binary") byte[] binary, @retrofit2.http.Field("date") LocalDate date, @retrofit2.http.Field("dateTime") OffsetDateTime dateTime, @retrofit2.http.Field("password") String password, @retrofit2.http.Field("callback") String paramCallback + @retrofit2.http.Field("number") BigDecimal number, @retrofit2.http.Field("double") Double _double, @retrofit2.http.Field("pattern_without_delimiter") String patternWithoutDelimiter, @retrofit2.http.Field("byte") byte[] _byte, @retrofit2.http.Field("integer") Integer integer, @retrofit2.http.Field("int32") Integer int32, @retrofit2.http.Field("int64") Long int64, @retrofit2.http.Field("float") Float _float, @retrofit2.http.Field("string") String string, @retrofit2.http.Field("binary") byte[] binary, @retrofit2.http.Field("date") LocalDate date, @retrofit2.http.Field("dateTime") DateTime dateTime, @retrofit2.http.Field("password") String password, @retrofit2.http.Field("callback") String paramCallback ); /** diff --git a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/model/FormatTest.java b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/model/FormatTest.java index bd87692a36..8ec80fccb7 100644 --- a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/model/FormatTest.java +++ b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/model/FormatTest.java @@ -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; /** * FormatTest @@ -63,7 +63,7 @@ public class FormatTest { private LocalDate date = null; @SerializedName("dateTime") - private OffsetDateTime dateTime = null; + private DateTime dateTime = null; @SerializedName("uuid") private UUID uuid = null; @@ -261,7 +261,7 @@ public class FormatTest { this.date = date; } - public FormatTest dateTime(OffsetDateTime dateTime) { + public FormatTest dateTime(DateTime dateTime) { this.dateTime = dateTime; return this; } @@ -271,11 +271,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; } diff --git a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java index 9c92756e16..447501906d 100644 --- a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java +++ b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java @@ -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; /** * MixedPropertiesAndAdditionalPropertiesClass @@ -38,7 +38,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass { private UUID uuid = null; @SerializedName("dateTime") - private OffsetDateTime dateTime = null; + private DateTime dateTime = null; @SerializedName("map") private Map map = null; @@ -61,7 +61,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass { this.uuid = uuid; } - public MixedPropertiesAndAdditionalPropertiesClass dateTime(OffsetDateTime dateTime) { + public MixedPropertiesAndAdditionalPropertiesClass dateTime(DateTime dateTime) { this.dateTime = dateTime; return this; } @@ -71,11 +71,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; } diff --git a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/model/Order.java b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/model/Order.java index 7856f4baf7..3249680760 100644 --- a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/model/Order.java +++ b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/model/Order.java @@ -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; /** * Order @@ -39,7 +39,7 @@ public class Order { private Integer quantity = null; @SerializedName("shipDate") - private OffsetDateTime shipDate = null; + private DateTime shipDate = null; /** * Order Status @@ -150,7 +150,7 @@ public class Order { this.quantity = quantity; } - public Order shipDate(OffsetDateTime shipDate) { + public Order shipDate(DateTime shipDate) { this.shipDate = shipDate; return this; } @@ -160,11 +160,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; } diff --git a/samples/client/petstore/java/retrofit2rx/.swagger-codegen/VERSION b/samples/client/petstore/java/retrofit2rx/.swagger-codegen/VERSION index f9f7450d13..7fea99011a 100644 --- a/samples/client/petstore/java/retrofit2rx/.swagger-codegen/VERSION +++ b/samples/client/petstore/java/retrofit2rx/.swagger-codegen/VERSION @@ -1 +1 @@ -2.3.0-SNAPSHOT \ No newline at end of file +2.2.3-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/java/retrofit2rx/build.gradle b/samples/client/petstore/java/retrofit2rx/build.gradle index fe0538acdd..42f189e96f 100644 --- a/samples/client/petstore/java/retrofit2rx/build.gradle +++ b/samples/client/petstore/java/retrofit2rx/build.gradle @@ -99,7 +99,7 @@ ext { swagger_annotations_version = "1.5.15" junit_version = "4.12" rx_java_version = "1.3.0" - threetenbp_version = "1.3.5" + jodatime_version = "2.9.9" } dependencies { @@ -110,7 +110,7 @@ dependencies { compile "io.reactivex:rxjava:$rx_java_version" compile "io.swagger:swagger-annotations:$swagger_annotations_version" compile "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version" - compile "org.threeten:threetenbp:$threetenbp_version" + compile "joda-time:joda-time:$jodatime_version" testCompile "junit:junit:$junit_version" } diff --git a/samples/client/petstore/java/retrofit2rx/build.sbt b/samples/client/petstore/java/retrofit2rx/build.sbt index 992dd1963d..6c15e1b665 100644 --- a/samples/client/petstore/java/retrofit2rx/build.sbt +++ b/samples/client/petstore/java/retrofit2rx/build.sbt @@ -16,7 +16,7 @@ lazy val root = (project in file(".")). "io.reactivex" % "rxjava" % "1.3.0" % "compile", "io.swagger" % "swagger-annotations" % "1.5.15" % "compile", "org.apache.oltu.oauth2" % "org.apache.oltu.oauth2.client" % "1.0.1" % "compile", - "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.11" % "test" ) diff --git a/samples/client/petstore/java/retrofit2rx/docs/FakeApi.md b/samples/client/petstore/java/retrofit2rx/docs/FakeApi.md index 43d5c4c20c..1b53ccee14 100644 --- a/samples/client/petstore/java/retrofit2rx/docs/FakeApi.md +++ b/samples/client/petstore/java/retrofit2rx/docs/FakeApi.md @@ -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 { @@ -302,7 +302,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] diff --git a/samples/client/petstore/java/retrofit2rx/docs/FormatTest.md b/samples/client/petstore/java/retrofit2rx/docs/FormatTest.md index c7a3acb3cb..06bed41723 100644 --- a/samples/client/petstore/java/retrofit2rx/docs/FormatTest.md +++ b/samples/client/petstore/java/retrofit2rx/docs/FormatTest.md @@ -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** | | diff --git a/samples/client/petstore/java/retrofit2rx/docs/MixedPropertiesAndAdditionalPropertiesClass.md b/samples/client/petstore/java/retrofit2rx/docs/MixedPropertiesAndAdditionalPropertiesClass.md index b12e2cd70e..349afef35a 100644 --- a/samples/client/petstore/java/retrofit2rx/docs/MixedPropertiesAndAdditionalPropertiesClass.md +++ b/samples/client/petstore/java/retrofit2rx/docs/MixedPropertiesAndAdditionalPropertiesClass.md @@ -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] diff --git a/samples/client/petstore/java/retrofit2rx/docs/Order.md b/samples/client/petstore/java/retrofit2rx/docs/Order.md index 268c617d1f..a1089f5384 100644 --- a/samples/client/petstore/java/retrofit2rx/docs/Order.md +++ b/samples/client/petstore/java/retrofit2rx/docs/Order.md @@ -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] diff --git a/samples/client/petstore/java/retrofit2rx/pom.xml b/samples/client/petstore/java/retrofit2rx/pom.xml index ce519bcf66..e7275be1be 100644 --- a/samples/client/petstore/java/retrofit2rx/pom.xml +++ b/samples/client/petstore/java/retrofit2rx/pom.xml @@ -195,9 +195,9 @@ ${oltu-version} - org.threeten - threetenbp - ${threetenbp-version} + joda-time + joda-time + ${jodatime-version} io.reactivex @@ -228,7 +228,7 @@ 1.5.15 2.3.0 1.3.0 - 1.3.5 + 2.9.9 1.0.1 4.12 diff --git a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/ApiClient.java index c5fc0a0872..428c7808e4 100644 --- a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/ApiClient.java @@ -8,7 +8,7 @@ import okhttp3.RequestBody; import okhttp3.ResponseBody; import org.apache.oltu.oauth2.client.request.OAuthClientRequest.AuthenticationRequestBuilder; import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder; -import org.threeten.bp.format.DateTimeFormatter; +import org.joda.time.format.DateTimeFormatter; import retrofit2.Converter; import retrofit2.Retrofit; import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; @@ -136,8 +136,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; } diff --git a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/JSON.java b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/JSON.java deleted file mode 100644 index 590495331b..0000000000 --- a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/JSON.java +++ /dev/null @@ -1,289 +0,0 @@ -/* - * Swagger Petstore - * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ - * - * OpenAPI spec version: 1.0.0 - * Contact: apiteam@swagger.io - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ - - -package io.swagger.client; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonParseException; -import com.google.gson.TypeAdapter; -import com.google.gson.internal.bind.util.ISO8601Utils; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; -import org.threeten.bp.LocalDate; -import org.threeten.bp.OffsetDateTime; -import org.threeten.bp.format.DateTimeFormatter; - -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; - -public class JSON { - private Gson gson; - private DateTypeAdapter dateTypeAdapter = new DateTypeAdapter(); - private SqlDateTypeAdapter sqlDateTypeAdapter = new SqlDateTypeAdapter(); - private OffsetDateTimeTypeAdapter offsetDateTimeTypeAdapter = new OffsetDateTimeTypeAdapter(); - 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(LocalDate.class, localDateTypeAdapter) - .create(); - } - - /** - * Get Gson. - * - * @return Gson - */ - public Gson getGson() { - return gson; - } - - /** - * Set Gson. - * - * @param gson Gson - * @return JSON - */ - public JSON setGson(Gson gson) { - this.gson = gson; - return this; - } - - /** - * Gson TypeAdapter for JSR310 OffsetDateTime type - */ - public static class OffsetDateTimeTypeAdapter extends TypeAdapter { - - private DateTimeFormatter formatter; - - public OffsetDateTimeTypeAdapter() { - this(DateTimeFormatter.ISO_OFFSET_DATE_TIME); - } - - public OffsetDateTimeTypeAdapter(DateTimeFormatter formatter) { - this.formatter = formatter; - } - - public void setFormat(DateTimeFormatter dateFormat) { - this.formatter = dateFormat; - } - - @Override - public void write(JsonWriter out, OffsetDateTime date) throws IOException { - if (date == null) { - out.nullValue(); - } else { - out.value(formatter.format(date)); - } - } - - @Override - public OffsetDateTime 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); - } - } - } - - /** - * Gson TypeAdapter for JSR310 LocalDate type - */ - public class LocalDateTypeAdapter extends TypeAdapter { - - private DateTimeFormatter formatter; - - public LocalDateTypeAdapter() { - this(DateTimeFormatter.ISO_LOCAL_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.format(date)); - } - } - - @Override - public LocalDate read(JsonReader in) throws IOException { - switch (in.peek()) { - case NULL: - in.nextNull(); - return null; - default: - String date = in.nextString(); - return LocalDate.parse(date, formatter); - } - } - } - - public JSON setOffsetDateTimeFormat(DateTimeFormatter dateFormat) { - offsetDateTimeTypeAdapter.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 { - - 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 { - - 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; - } - -} diff --git a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/api/FakeApi.java b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/api/FakeApi.java index 673afc53fd..3c258bd88a 100644 --- a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/api/FakeApi.java +++ b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/api/FakeApi.java @@ -9,8 +9,8 @@ import okhttp3.RequestBody; 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; @@ -100,7 +100,7 @@ public interface FakeApi { @retrofit2.http.FormUrlEncoded @POST("fake") Observable testEndpointParameters( - @retrofit2.http.Field("number") BigDecimal number, @retrofit2.http.Field("double") Double _double, @retrofit2.http.Field("pattern_without_delimiter") String patternWithoutDelimiter, @retrofit2.http.Field("byte") byte[] _byte, @retrofit2.http.Field("integer") Integer integer, @retrofit2.http.Field("int32") Integer int32, @retrofit2.http.Field("int64") Long int64, @retrofit2.http.Field("float") Float _float, @retrofit2.http.Field("string") String string, @retrofit2.http.Field("binary") byte[] binary, @retrofit2.http.Field("date") LocalDate date, @retrofit2.http.Field("dateTime") OffsetDateTime dateTime, @retrofit2.http.Field("password") String password, @retrofit2.http.Field("callback") String paramCallback + @retrofit2.http.Field("number") BigDecimal number, @retrofit2.http.Field("double") Double _double, @retrofit2.http.Field("pattern_without_delimiter") String patternWithoutDelimiter, @retrofit2.http.Field("byte") byte[] _byte, @retrofit2.http.Field("integer") Integer integer, @retrofit2.http.Field("int32") Integer int32, @retrofit2.http.Field("int64") Long int64, @retrofit2.http.Field("float") Float _float, @retrofit2.http.Field("string") String string, @retrofit2.http.Field("binary") byte[] binary, @retrofit2.http.Field("date") LocalDate date, @retrofit2.http.Field("dateTime") DateTime dateTime, @retrofit2.http.Field("password") String password, @retrofit2.http.Field("callback") String paramCallback ); /** diff --git a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/model/FormatTest.java b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/model/FormatTest.java index bd87692a36..8ec80fccb7 100644 --- a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/model/FormatTest.java +++ b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/model/FormatTest.java @@ -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; /** * FormatTest @@ -63,7 +63,7 @@ public class FormatTest { private LocalDate date = null; @SerializedName("dateTime") - private OffsetDateTime dateTime = null; + private DateTime dateTime = null; @SerializedName("uuid") private UUID uuid = null; @@ -261,7 +261,7 @@ public class FormatTest { this.date = date; } - public FormatTest dateTime(OffsetDateTime dateTime) { + public FormatTest dateTime(DateTime dateTime) { this.dateTime = dateTime; return this; } @@ -271,11 +271,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; } diff --git a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java index 9c92756e16..447501906d 100644 --- a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java +++ b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java @@ -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; /** * MixedPropertiesAndAdditionalPropertiesClass @@ -38,7 +38,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass { private UUID uuid = null; @SerializedName("dateTime") - private OffsetDateTime dateTime = null; + private DateTime dateTime = null; @SerializedName("map") private Map map = null; @@ -61,7 +61,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass { this.uuid = uuid; } - public MixedPropertiesAndAdditionalPropertiesClass dateTime(OffsetDateTime dateTime) { + public MixedPropertiesAndAdditionalPropertiesClass dateTime(DateTime dateTime) { this.dateTime = dateTime; return this; } @@ -71,11 +71,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; } diff --git a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/model/Order.java b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/model/Order.java index 7856f4baf7..3249680760 100644 --- a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/model/Order.java +++ b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/model/Order.java @@ -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; /** * Order @@ -39,7 +39,7 @@ public class Order { private Integer quantity = null; @SerializedName("shipDate") - private OffsetDateTime shipDate = null; + private DateTime shipDate = null; /** * Order Status @@ -150,7 +150,7 @@ public class Order { this.quantity = quantity; } - public Order shipDate(OffsetDateTime shipDate) { + public Order shipDate(DateTime shipDate) { this.shipDate = shipDate; return this; } @@ -160,11 +160,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; } diff --git a/samples/client/petstore/java/retrofit2rx2/.swagger-codegen/VERSION b/samples/client/petstore/java/retrofit2rx2/.swagger-codegen/VERSION index f9f7450d13..7fea99011a 100644 --- a/samples/client/petstore/java/retrofit2rx2/.swagger-codegen/VERSION +++ b/samples/client/petstore/java/retrofit2rx2/.swagger-codegen/VERSION @@ -1 +1 @@ -2.3.0-SNAPSHOT \ No newline at end of file +2.2.3-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/java/retrofit2rx2/build.gradle b/samples/client/petstore/java/retrofit2rx2/build.gradle index 7ec34d974c..7d35c75923 100644 --- a/samples/client/petstore/java/retrofit2rx2/build.gradle +++ b/samples/client/petstore/java/retrofit2rx2/build.gradle @@ -99,7 +99,7 @@ ext { swagger_annotations_version = "1.5.15" junit_version = "4.12" rx_java_version = "2.1.1" - threetenbp_version = "1.3.5" + jodatime_version = "2.9.9" } dependencies { @@ -110,7 +110,7 @@ dependencies { compile "io.reactivex.rxjava2:rxjava:$rx_java_version" compile "io.swagger:swagger-annotations:$swagger_annotations_version" compile "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version" - compile "org.threeten:threetenbp:$threetenbp_version" + compile "joda-time:joda-time:$jodatime_version" testCompile "junit:junit:$junit_version" } diff --git a/samples/client/petstore/java/retrofit2rx2/build.sbt b/samples/client/petstore/java/retrofit2rx2/build.sbt index d99837ab11..181f8040a7 100644 --- a/samples/client/petstore/java/retrofit2rx2/build.sbt +++ b/samples/client/petstore/java/retrofit2rx2/build.sbt @@ -16,7 +16,7 @@ lazy val root = (project in file(".")). "io.reactivex.rxjava2" % "rxjava" % "2.1.1" % "compile", "io.swagger" % "swagger-annotations" % "1.5.15" % "compile", "org.apache.oltu.oauth2" % "org.apache.oltu.oauth2.client" % "1.0.1" % "compile", - "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.11" % "test" ) diff --git a/samples/client/petstore/java/retrofit2rx2/docs/FakeApi.md b/samples/client/petstore/java/retrofit2rx2/docs/FakeApi.md index 43d5c4c20c..1b53ccee14 100644 --- a/samples/client/petstore/java/retrofit2rx2/docs/FakeApi.md +++ b/samples/client/petstore/java/retrofit2rx2/docs/FakeApi.md @@ -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 { @@ -302,7 +302,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] diff --git a/samples/client/petstore/java/retrofit2rx2/docs/FormatTest.md b/samples/client/petstore/java/retrofit2rx2/docs/FormatTest.md index c7a3acb3cb..06bed41723 100644 --- a/samples/client/petstore/java/retrofit2rx2/docs/FormatTest.md +++ b/samples/client/petstore/java/retrofit2rx2/docs/FormatTest.md @@ -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** | | diff --git a/samples/client/petstore/java/retrofit2rx2/docs/MixedPropertiesAndAdditionalPropertiesClass.md b/samples/client/petstore/java/retrofit2rx2/docs/MixedPropertiesAndAdditionalPropertiesClass.md index b12e2cd70e..349afef35a 100644 --- a/samples/client/petstore/java/retrofit2rx2/docs/MixedPropertiesAndAdditionalPropertiesClass.md +++ b/samples/client/petstore/java/retrofit2rx2/docs/MixedPropertiesAndAdditionalPropertiesClass.md @@ -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] diff --git a/samples/client/petstore/java/retrofit2rx2/docs/Order.md b/samples/client/petstore/java/retrofit2rx2/docs/Order.md index 268c617d1f..a1089f5384 100644 --- a/samples/client/petstore/java/retrofit2rx2/docs/Order.md +++ b/samples/client/petstore/java/retrofit2rx2/docs/Order.md @@ -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] diff --git a/samples/client/petstore/java/retrofit2rx2/pom.xml b/samples/client/petstore/java/retrofit2rx2/pom.xml index b09b4ecea4..e30ee231a5 100644 --- a/samples/client/petstore/java/retrofit2rx2/pom.xml +++ b/samples/client/petstore/java/retrofit2rx2/pom.xml @@ -195,9 +195,9 @@ ${oltu-version} - org.threeten - threetenbp - ${threetenbp-version} + joda-time + joda-time + ${jodatime-version} io.reactivex.rxjava2 @@ -228,7 +228,7 @@ 1.5.15 2.3.0 2.1.1 - 1.3.5 + 2.9.9 1.0.1 4.12 diff --git a/samples/client/petstore/java/retrofit2rx2/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/retrofit2rx2/src/main/java/io/swagger/client/ApiClient.java index c348b2a162..08eb0121f0 100644 --- a/samples/client/petstore/java/retrofit2rx2/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/retrofit2rx2/src/main/java/io/swagger/client/ApiClient.java @@ -8,7 +8,7 @@ import okhttp3.RequestBody; import okhttp3.ResponseBody; import org.apache.oltu.oauth2.client.request.OAuthClientRequest.AuthenticationRequestBuilder; import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder; -import org.threeten.bp.format.DateTimeFormatter; +import org.joda.time.format.DateTimeFormatter; import retrofit2.Converter; import retrofit2.Retrofit; import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; @@ -137,8 +137,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; } diff --git a/samples/client/petstore/java/retrofit2rx2/src/main/java/io/swagger/client/JSON.java b/samples/client/petstore/java/retrofit2rx2/src/main/java/io/swagger/client/JSON.java deleted file mode 100644 index 590495331b..0000000000 --- a/samples/client/petstore/java/retrofit2rx2/src/main/java/io/swagger/client/JSON.java +++ /dev/null @@ -1,289 +0,0 @@ -/* - * Swagger Petstore - * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ - * - * OpenAPI spec version: 1.0.0 - * Contact: apiteam@swagger.io - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ - - -package io.swagger.client; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonParseException; -import com.google.gson.TypeAdapter; -import com.google.gson.internal.bind.util.ISO8601Utils; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; -import org.threeten.bp.LocalDate; -import org.threeten.bp.OffsetDateTime; -import org.threeten.bp.format.DateTimeFormatter; - -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; - -public class JSON { - private Gson gson; - private DateTypeAdapter dateTypeAdapter = new DateTypeAdapter(); - private SqlDateTypeAdapter sqlDateTypeAdapter = new SqlDateTypeAdapter(); - private OffsetDateTimeTypeAdapter offsetDateTimeTypeAdapter = new OffsetDateTimeTypeAdapter(); - 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(LocalDate.class, localDateTypeAdapter) - .create(); - } - - /** - * Get Gson. - * - * @return Gson - */ - public Gson getGson() { - return gson; - } - - /** - * Set Gson. - * - * @param gson Gson - * @return JSON - */ - public JSON setGson(Gson gson) { - this.gson = gson; - return this; - } - - /** - * Gson TypeAdapter for JSR310 OffsetDateTime type - */ - public static class OffsetDateTimeTypeAdapter extends TypeAdapter { - - private DateTimeFormatter formatter; - - public OffsetDateTimeTypeAdapter() { - this(DateTimeFormatter.ISO_OFFSET_DATE_TIME); - } - - public OffsetDateTimeTypeAdapter(DateTimeFormatter formatter) { - this.formatter = formatter; - } - - public void setFormat(DateTimeFormatter dateFormat) { - this.formatter = dateFormat; - } - - @Override - public void write(JsonWriter out, OffsetDateTime date) throws IOException { - if (date == null) { - out.nullValue(); - } else { - out.value(formatter.format(date)); - } - } - - @Override - public OffsetDateTime 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); - } - } - } - - /** - * Gson TypeAdapter for JSR310 LocalDate type - */ - public class LocalDateTypeAdapter extends TypeAdapter { - - private DateTimeFormatter formatter; - - public LocalDateTypeAdapter() { - this(DateTimeFormatter.ISO_LOCAL_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.format(date)); - } - } - - @Override - public LocalDate read(JsonReader in) throws IOException { - switch (in.peek()) { - case NULL: - in.nextNull(); - return null; - default: - String date = in.nextString(); - return LocalDate.parse(date, formatter); - } - } - } - - public JSON setOffsetDateTimeFormat(DateTimeFormatter dateFormat) { - offsetDateTimeTypeAdapter.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 { - - 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 { - - 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; - } - -} diff --git a/samples/client/petstore/java/retrofit2rx2/src/main/java/io/swagger/client/api/FakeApi.java b/samples/client/petstore/java/retrofit2rx2/src/main/java/io/swagger/client/api/FakeApi.java index 382733eb12..98766c0309 100644 --- a/samples/client/petstore/java/retrofit2rx2/src/main/java/io/swagger/client/api/FakeApi.java +++ b/samples/client/petstore/java/retrofit2rx2/src/main/java/io/swagger/client/api/FakeApi.java @@ -9,8 +9,8 @@ import okhttp3.RequestBody; 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; @@ -100,7 +100,7 @@ public interface FakeApi { @retrofit2.http.FormUrlEncoded @POST("fake") Observable testEndpointParameters( - @retrofit2.http.Field("number") BigDecimal number, @retrofit2.http.Field("double") Double _double, @retrofit2.http.Field("pattern_without_delimiter") String patternWithoutDelimiter, @retrofit2.http.Field("byte") byte[] _byte, @retrofit2.http.Field("integer") Integer integer, @retrofit2.http.Field("int32") Integer int32, @retrofit2.http.Field("int64") Long int64, @retrofit2.http.Field("float") Float _float, @retrofit2.http.Field("string") String string, @retrofit2.http.Field("binary") byte[] binary, @retrofit2.http.Field("date") LocalDate date, @retrofit2.http.Field("dateTime") OffsetDateTime dateTime, @retrofit2.http.Field("password") String password, @retrofit2.http.Field("callback") String paramCallback + @retrofit2.http.Field("number") BigDecimal number, @retrofit2.http.Field("double") Double _double, @retrofit2.http.Field("pattern_without_delimiter") String patternWithoutDelimiter, @retrofit2.http.Field("byte") byte[] _byte, @retrofit2.http.Field("integer") Integer integer, @retrofit2.http.Field("int32") Integer int32, @retrofit2.http.Field("int64") Long int64, @retrofit2.http.Field("float") Float _float, @retrofit2.http.Field("string") String string, @retrofit2.http.Field("binary") byte[] binary, @retrofit2.http.Field("date") LocalDate date, @retrofit2.http.Field("dateTime") DateTime dateTime, @retrofit2.http.Field("password") String password, @retrofit2.http.Field("callback") String paramCallback ); /** diff --git a/samples/client/petstore/java/retrofit2rx2/src/main/java/io/swagger/client/model/FormatTest.java b/samples/client/petstore/java/retrofit2rx2/src/main/java/io/swagger/client/model/FormatTest.java index bd87692a36..8ec80fccb7 100644 --- a/samples/client/petstore/java/retrofit2rx2/src/main/java/io/swagger/client/model/FormatTest.java +++ b/samples/client/petstore/java/retrofit2rx2/src/main/java/io/swagger/client/model/FormatTest.java @@ -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; /** * FormatTest @@ -63,7 +63,7 @@ public class FormatTest { private LocalDate date = null; @SerializedName("dateTime") - private OffsetDateTime dateTime = null; + private DateTime dateTime = null; @SerializedName("uuid") private UUID uuid = null; @@ -261,7 +261,7 @@ public class FormatTest { this.date = date; } - public FormatTest dateTime(OffsetDateTime dateTime) { + public FormatTest dateTime(DateTime dateTime) { this.dateTime = dateTime; return this; } @@ -271,11 +271,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; } diff --git a/samples/client/petstore/java/retrofit2rx2/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java b/samples/client/petstore/java/retrofit2rx2/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java index 9c92756e16..447501906d 100644 --- a/samples/client/petstore/java/retrofit2rx2/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java +++ b/samples/client/petstore/java/retrofit2rx2/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java @@ -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; /** * MixedPropertiesAndAdditionalPropertiesClass @@ -38,7 +38,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass { private UUID uuid = null; @SerializedName("dateTime") - private OffsetDateTime dateTime = null; + private DateTime dateTime = null; @SerializedName("map") private Map map = null; @@ -61,7 +61,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass { this.uuid = uuid; } - public MixedPropertiesAndAdditionalPropertiesClass dateTime(OffsetDateTime dateTime) { + public MixedPropertiesAndAdditionalPropertiesClass dateTime(DateTime dateTime) { this.dateTime = dateTime; return this; } @@ -71,11 +71,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; } diff --git a/samples/client/petstore/java/retrofit2rx2/src/main/java/io/swagger/client/model/Order.java b/samples/client/petstore/java/retrofit2rx2/src/main/java/io/swagger/client/model/Order.java index 7856f4baf7..3249680760 100644 --- a/samples/client/petstore/java/retrofit2rx2/src/main/java/io/swagger/client/model/Order.java +++ b/samples/client/petstore/java/retrofit2rx2/src/main/java/io/swagger/client/model/Order.java @@ -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; /** * Order @@ -39,7 +39,7 @@ public class Order { private Integer quantity = null; @SerializedName("shipDate") - private OffsetDateTime shipDate = null; + private DateTime shipDate = null; /** * Order Status @@ -150,7 +150,7 @@ public class Order { this.quantity = quantity; } - public Order shipDate(OffsetDateTime shipDate) { + public Order shipDate(DateTime shipDate) { this.shipDate = shipDate; return this; } @@ -160,11 +160,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; }