Skip to content
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

[Android] Client doesn't call setDateFormat() on GsonBuilder object correctly #3590

Open
martinkbrown opened this issue Aug 15, 2016 · 5 comments

Comments

@martinkbrown
Copy link
Contributor

Description

I get ApiException when Swagger tries to retrieve the following JSON:
{"apiVersion":1,"providerID":9999999999,"timeStamp":"2016-08-15T14:38:36.172Z"}

The root cause is that JsonUtil.java calls

gsonBuilder.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");

instead of calling it with single quotes around the "Z"

gsonBuilder.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");

2.0
Swagger declaration file content or url
Command line used for generation
Steps to reproduce

Specify the format of a yaml field to "date-time"

Related issues
Suggest a Fix

Add single quotes around the "Z" character in the String argument to gsonBuilder.setDateFormat()

@wing328
Copy link
Contributor

wing328 commented Aug 16, 2016

@martinkbrown thanks for reporting the issue with a suggested fix.

May I know if you've cycle to contribute a PR with the fix?

@martinkbrown
Copy link
Contributor Author

Yes I will fix this and push my changes.

Thanks.

On Tue, Aug 16, 2016 at 10:19 AM, wing328 notifications@github.com wrote:

@martinkbrown https://github.com/martinkbrown thanks for reporting the
issue with a suggested fix.

May I know if you've cycle to contribute a PR with the fix?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#3590 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAmgXfdi1tGcCJM5Fu1J6nXStyCEmFWoks5qgccBgaJpZM4JkgmE
.

Martin K. Brown

@cbornet
Copy link
Contributor

cbornet commented Aug 18, 2016

A more complete solution would be to use https://github.com/google/gson/blob/master/extras/src/main/java/com/google/gson/typeadapters/UtcDateTypeAdapter.java or joda.
If you only set 'Z', you can't parse time offset as specified in rfc3339.

@karakani
Copy link

karakani commented Jan 1, 2017

Single quoted 'Z' stands for the date is in GMT.
So, 'XXX' would be nice for various environment.

gsonBuilder.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");

https://developer.android.com/reference/java/text/SimpleDateFormat.html

@cbornet
Copy link
Contributor

cbornet commented Jan 1, 2017

If I'm not mistaken, XXX is not available for older versions of the android API.

@wing328 wing328 modified the milestones: Future, v2.2.2 Feb 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants