-
Notifications
You must be signed in to change notification settings - Fork 6k
[Scala][Java][okhttp] Fix Gson parsing of Joda DateTime without millis #4473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Yes but dateOptionalTimeParser should be used instead. |
|
@cbornet Why |
|
@cbornet I took a closer look at the grammars accepted by |
|
@cbornet I noticed that |
The DateTimeFormatter returned by ISODateTimeFormat.dateTime() only parses dates with millisecond values, and throws IllegalArgumentException when milliseconds are not present. The date-time construct from RFC 3339 Section 5.6 referenced by the Swagger/OpenAPI spec allows fractional second values to be omitted. This results in valid date-time values being rejected by the generated code. This commit fixes the problem by using .dateOptionalTimeParser() for parsing, which correctly handles date-time values without fractional seconds. A previous version of this commit used .dateTimeParser(), which accepted a time without a date and was considered too liberal. Note that .dateTime() must still be used for printing, which is not supported by .dateTimeParser(). Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
As in the previous commit, which fixed Java generators, ISOISODateTimeFormat.dateOptionalTimeParser() should be used for date-time parsing and ISOISODateTimeFormat.dateTime() for printing. Apply the same change to akka-scala. Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
e26b85b to
5765cd5
Compare
|
PR updated and CI passed. I included the analogous akka-scala change as a separate commit that can easily be dropped if it should be handled separately. |
|
👍 |
|
@kevinoid thanks for the contribution, especially to the |
|
@wing328 Thanks for reviewing and merging it! |
* Fix Gson parsing of Joda DateTime without millis The DateTimeFormatter returned by ISODateTimeFormat.dateTime() only parses dates with millisecond values, and throws IllegalArgumentException when milliseconds are not present. The date-time construct from RFC 3339 Section 5.6 referenced by the Swagger/OpenAPI spec allows fractional second values to be omitted. This results in valid date-time values being rejected by the generated code. This commit fixes the problem by using .dateOptionalTimeParser() for parsing, which correctly handles date-time values without fractional seconds. A previous version of this commit used .dateTimeParser(), which accepted a time without a date and was considered too liberal. Note that .dateTime() must still be used for printing, which is not supported by .dateTimeParser(). Signed-off-by: Kevin Locke <kevin@kevinlocke.name> * Fix akka-scala date-time parser with Joda As in the previous commit, which fixed Java generators, ISOISODateTimeFormat.dateOptionalTimeParser() should be used for date-time parsing and ISOISODateTimeFormat.dateTime() for printing. Apply the same change to akka-scala. Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
PR checklist
./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.shand./bin/security/{LANG}-petstore.shif updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates)2.3.0branch for breaking (non-backward compatible) changes.Description of the PR
The
DateTimeFormatterreturned byISODateTimeFormat.dateTime()only parses dates with millisecond values, and throwsIllegalArgumentExceptionwhen milliseconds are not present. Thedate-time construct from RFC 3339 Section 5.6 referenced by the Swagger/OpenAPI spec allows fractional second values to be omitted. This results in valid date-time values being rejected by the generated code.
This PR fixes the problem by using
ISODateTimeFormat.dateTimeParser()for parsing, which correctly handles date-time values without fractional seconds. Note that.dateTime()muststill be used for printing, which is not supported by
.dateTimeParser().