Skip to content

Commit

Permalink
no gson internals for date parsing/formatting
Browse files Browse the repository at this point in the history
Reapply changes from kubernetes-client#366 to the code generated by openapi-generator,
and keep the JSON file pinned (ignored by the generator) until those
changes make it into the generator.
  • Loading branch information
fabiokung committed Oct 23, 2019
1 parent 91d0d5a commit 7ab84da
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 3 additions & 0 deletions kubernetes/.openapi-generator-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
*sbt*
git_push.sh
README.md

# Remove when changes in kubernetes-client/java#366 make into upstream openapi-generator
src/main/java/io/kubernetes/client/JSON.java
8 changes: 3 additions & 5 deletions kubernetes/src/main/java/io/kubernetes/client/JSON.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
import com.google.gson.TypeAdapter;
import com.google.gson.internal.bind.util.ISO8601Utils;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.google.gson.JsonElement;
Expand All @@ -37,7 +36,6 @@
import java.lang.reflect.Type;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -318,7 +316,7 @@ public java.sql.Date read(JsonReader in) throws IOException {
if (dateFormat != null) {
return new java.sql.Date(dateFormat.parse(date).getTime());
}
return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime());
return new java.sql.Date(ISODateTimeFormat.basicDateTime().parseMillis(date));
} catch (ParseException e) {
throw new JsonParseException(e);
}
Expand Down Expand Up @@ -353,7 +351,7 @@ public void write(JsonWriter out, Date date) throws IOException {
if (dateFormat != null) {
value = dateFormat.format(date);
} else {
value = ISO8601Utils.format(date, true);
value = ISODateTimeFormat.basicDateTime().print(date.getTime());
}
out.value(value);
}
Expand All @@ -372,7 +370,7 @@ public Date read(JsonReader in) throws IOException {
if (dateFormat != null) {
return dateFormat.parse(date);
}
return ISO8601Utils.parse(date, new ParsePosition(0));
return ISODateTimeFormat.basicDateTime().parseDateTime(date).toDate();
} catch (ParseException e) {
throw new JsonParseException(e);
}
Expand Down

0 comments on commit 7ab84da

Please sign in to comment.