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

[JAVA] Client generated with deprecated code. #1053

Closed
ghost opened this issue Sep 18, 2018 · 8 comments
Closed

[JAVA] Client generated with deprecated code. #1053

ghost opened this issue Sep 18, 2018 · 8 comments

Comments

@ghost
Copy link

ghost commented Sep 18, 2018

Description

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.

Swagger-codegen version

2.3.1

Configuration

config.json:

{
"library":"resttemplate",
"modelPackage":"packageName",
"useBeanValidation":"true",
"hideGenerationTimestamp":"true",
"dateLibrary":"java8"
}
@chenjianjx
Copy link

+1

@wing328
Copy link
Member

wing328 commented Jan 30, 2019

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)

@nhultz
Copy link

nhultz commented Feb 12, 2019

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.

@zawataki
Copy link

I ran into the same problem using the latest v4.2.2 release and dateLibrary: java8.

@Andy-L
Copy link

Andy-L commented Aug 14, 2020

I am running into the same problem using the v4.2.3 release and dateLibrary: java8.

@wing328
Copy link
Member

wing328 commented Aug 14, 2020

There's a PR to address it - #5786

Can you please test to see if it resolves the issue?

@zawataki
Copy link

zawataki commented Sep 7, 2020

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

@zawataki
Copy link

zawataki commented Sep 7, 2020

@emile-jumo Can you close this issue because the issue has been resolved? Thank you.

@wing328 wing328 closed this as completed Sep 7, 2020
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

5 participants