From 1953fe0d790cab820518e30f412c6bb511bba525 Mon Sep 17 00:00:00 2001 From: Lars Wander Date: Thu, 3 Aug 2017 14:18:39 -0400 Subject: [PATCH] [Java] Fix okhttp-gson datetime converter compilation --- .../Java/libraries/okhttp-gson/JSON.mustache | 12 +++++++----- .../resources/Java/libraries/retrofit2/JSON.mustache | 5 ++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/JSON.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/JSON.mustache index 5ee0a44b58b..ce131c40f48 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/JSON.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/JSON.mustache @@ -13,6 +13,7 @@ import com.google.gson.stream.JsonWriter; import org.joda.time.DateTime; import org.joda.time.LocalDate; import org.joda.time.format.DateTimeFormatter; +import org.joda.time.format.DateTimeFormatterBuilder; import org.joda.time.format.ISODateTimeFormat; {{/joda}} {{#threetenbp}} @@ -132,11 +133,12 @@ public class JSON { */ public static class DateTimeTypeAdapter extends TypeAdapter { - private final DateTimeFormatter parseFormatter = ISODateTimeFormat.dateOptionalTimeParser(); - private final DateTimeFormatter printFormatter = ISODateTimeFormat.dateTime(); + private DateTimeFormatter formatter; public DateTimeTypeAdapter() { - this(ISODateTimeFormat.dateTime().withOffsetParsed()); + this(new DateTimeFormatterBuilder() + .append(ISODateTimeFormat.dateTime().getPrinter(), ISODateTimeFormat.dateOptionalTimeParser().getParser()) + .toFormatter()); } public DateTimeTypeAdapter(DateTimeFormatter formatter) { @@ -152,7 +154,7 @@ public class JSON { if (date == null) { out.nullValue(); } else { - out.value(printFormatter.print(date)); + out.value(formatter.print(date)); } } @@ -164,7 +166,7 @@ public class JSON { return null; default: String date = in.nextString(); - return parseFormatter.parseDateTime(date); + return formatter.parseDateTime(date); } } } diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/JSON.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/JSON.mustache index 79c398fc1b9..9acd505b763 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/JSON.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/JSON.mustache @@ -13,6 +13,7 @@ import com.google.gson.stream.JsonWriter; import org.joda.time.DateTime; import org.joda.time.LocalDate; import org.joda.time.format.DateTimeFormatter; +import org.joda.time.format.DateTimeFormatterBuilder; import org.joda.time.format.ISODateTimeFormat; {{/joda}} {{#threetenbp}} @@ -91,7 +92,9 @@ public class JSON { private DateTimeFormatter formatter; public DateTimeTypeAdapter() { - this(ISODateTimeFormat.dateTime().withOffsetParsed()); + this(new DateTimeFormatterBuilder() + .append(ISODateTimeFormat.dateTime().getPrinter(), ISODateTimeFormat.dateOptionalTimeParser().getParser()) + .toFormatter()); } public DateTimeTypeAdapter(DateTimeFormatter formatter) {