Closed tadhgpearson closed 8 years ago
The best way is to use the joda date lib (or JSR310 on java8). It has been implemented on feign and retrofit clients (generate with -DdateLibrary=joda) When all java clients are done, we will be able to switch the default date lib to joda.
Actually the default(jersey) and jersey2 libs also have joda support
Sure. I prefer Joda too, or even Java 8, and I'd be happy if you'd make it the default. But this is the default option right now and it's broken. If you agree it's an issue, and you have a preferred approach to fixing it, I'd be happy to do a fix and provide a pull request.
In the end it will be the default. For now you can use -DdateLibrary=joda
Sure... but I also need it to work with the default option. For example, right now on editor.swagger.io, you can't choose the options, so the default code output is broken.
@tadhgpearson yes, editor.swagger.io only uses the default option. Please pull the latest master to generate the SDK instead: https://github.com/swagger-api/swagger-codegen#getting-started (there are more than 120+ enhancements,bug fixes since v2.1.6 release)
Thanks for the clarification @wing328
Yes, I am using the latest master, and the issue still exists in it. I didn't realize that this wasn't the same as v2.1.6, sorry about that.
When generating the Java client, did you use -DdateLibrary=joda
as suggested by @cbornet ?
Which Java HTTP library did you use? default, jersey2, okhttp-gson, etc?
I'm using the default HTTP library. Seeing the resolution, does this mean that support for java.util.Date has been removed?
You can still use it with -DdateLibrary=legacy but I encourage you to use joda if you can.
LOL - no encouragement needed!
Description
The generated Java client does not correctly parse the Swagger date format from API responses.
According to the swagger spec a response field of type string, format date must return a full-date defined by RFC 3339 which specifies the format as
This is not supported by the default Java client, which generates using a single date format, used for both date and date-time which is
This means simple date fields are not supported and cause the client to throw an InvalidFormatException during the parsing of a response model which contains Date fields..
Swagger-codegen version
2.1.6
Swagger declaration file content or url
Source swagger file is https://github.com/amadeus-travel-innovation-sandbox/sandbox-content/blob/master/swagger.yml
Command line used for generation
java -jar modules\swagger-codegen-cli\target\swagger-codegen-cli.jar generate -i https://raw.githubusercontent.com/amadeus-travel-innovation-sandbox/sandbox-content/master/swagger.yml -l java -o /java-client
Steps to reproduce
Related issues
No noted related issues
Suggest a Fix
There are two good approaches to this. Either define a date and a dateTime formatter, and use them appropriately, or define a looser date parser for all API responses that can handle any valid ISO Date/Time