I use swagger to define my API and generate clients form the swagger spec. When I generated the Java client using swagger-codegen a class called RFC3339DateFormat.java was generated and it extends ISO8601DateFormat which is deprecated.
Do you suggest that I replace it manually with the preferred class StdDateFormat? Or is there configuration that I should set to use StdDateFormat rather.
2.3.1
config.json:
{
"library":"resttemplate",
"modelPackage":"packageName",
"useBeanValidation":"true",
"hideGenerationTimestamp":"true",
"dateLibrary":"java8"
}
+1
Have you considered the dateLibrary option?
dateLibrary
Option. Date library to use
joda - Joda (for legacy app only)
legacy - Legacy java.util.Date (if you really have a good reason not to use threetenbp
java8-localdatetime - Java 8 using LocalDateTime (for legacy app only)
java8 - Java 8 native JSR310 (preferred for jdk 1.8+) - note: this also sets "java8" to true
threetenbp - Backport of JSR310 (preferred for jdk < 1.8)
I ran into this same problem today while using dateLibrary: java8 in my config.
Looks like the java generator is pinned to use jackson-databind:2.8.11.3 and ISO8601DateFormat was marked as deprecated in 2.9 and above.
If you use your own build.gradle (like I was trying to do) that uses the later version of jackson-databind, you'll get the deprecated warning.
Confirmed this is still happening as of the 4.0.0-beta2 release just to make sure.
I ran into the same problem using the latest v4.2.2 release and dateLibrary: java8.
I am running into the same problem using the v4.2.3 release and dateLibrary: java8.
There's a PR to address it - https://github.com/OpenAPITools/openapi-generator/pull/5786
Can you please test to see if it resolves the issue?
I have confirmed the issue has been resolved by the latest release v5.0.0-beta2. The RFC3339DateFormat class extends DateFormat class now as below:
package org.openapitools;
import com.fasterxml.jackson.databind.util.StdDateFormat;
import java.text.DateFormat;
import java.text.FieldPosition;
import java.text.ParsePosition;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
public class RFC3339DateFormat extends DateFormat {
private static final long serialVersionUID = 1L;
private static final TimeZone TIMEZONE_Z = TimeZone.getTimeZone("UTC");
private final StdDateFormat fmt = new StdDateFormat()
.withTimeZone(TIMEZONE_Z)
.withColonInTimeZone(true);
public RFC3339DateFormat() {
this.calendar = new GregorianCalendar();
}
@Override
public Date parse(String source, ParsePosition pos) {
return fmt.parse(source, pos);
}
@Override
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
return fmt.format(date, toAppendTo, fieldPosition);
}
@Override
public Object clone() {
return this;
}
}
The command I executed to test is below:
$ docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:v5.0.0-beta2 generate -i https://raw.githubusercontent.com/zawataki/sample-api-interface/master/yaml-unresolved/swagger.yaml -g spring -o /local/5.0.0-beta2-spring --additional-properties=dateLibrary=java8
@emile-jumo Can you close this issue because the issue has been resolved? Thank you.
Most helpful comment
I ran into this same problem today while using
dateLibrary: java8in my config.Looks like the java generator is pinned to use
jackson-databind:2.8.11.3and ISO8601DateFormat was marked as deprecated in2.9and above.If you use your own
build.gradle(like I was trying to do) that uses the later version of jackson-databind, you'll get the deprecated warning.Confirmed this is still happening as of the
4.0.0-beta2release just to make sure.