openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG] [JAVA | CLIENT Generator | Spring Boot] RestTemplate client incompatibility between JsonDeserializer and ThreeTenDateTimeDeserializerBase

Open delitahub opened this issue 5 years ago • 5 comments

Description

I have a Spring boot service that needs to make a call to another Spring boot service. Tried generating a RestTemplate client with the java generator to be used within the first spring boot service. However, among the client classes that are generated the CustomInstantDeserializer can't compile due to an incompatibility between com.fasterxml.jackson.databind.JsonDeserializer and com.fasterxml.jackson.datatype.threetenbp.deser.ThreeTenDateTimeDeserializerBase.

openapi-generator version

openapi-generator-maven-plugin 4.2.3

Generated client within project that had spring boot dependencies: spring-boot-starter-parent 2.2.4.RELEASE spring-boot-starter-web 2.2.4.RELEASE org.openapitools.jackson-databind-nullable 0.2.1 org.openapitools.openapi-generator 4.2.3

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  version: 1.0.0
  title: Petstore
paths: 
  /pets:
    get:
      description: Returns all pets from the system that the user has access to
      operationId: getAllPets
      responses:
        '200':
          description: A list of pets.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Pet'
components:
  schemas:
    Pet:
      type: object
      properties:
        name:
          type: string
        petType:
          type: string
Command line used for generation

pom.zip

Steps to reproduce

Use the maven plugin to generate the RestTemplate client from the yml. This will create client classes including the CustomInstantDeserializer.java. On compilation an error will be thrown saying the following message:

[ERROR] /src/gen/java/main/com/store/pets/CustomInstantDeserializer.java:[31,8] com.store.pets.CustomInstantDeserializer is not abstract and does not override abstract method withLeniency(java.lang.Boolean) in com.fasterxml.jackson.datatype.threetenbp.deser.ThreeTenDateTimeDeserializerBase [ERROR] /target/generated-sources/openapi/src/gen/java/main/com/store/pets/CustomInstantDeserializer.java:[150,33] withDateFormat(org.threeten.bp.format.DateTimeFormatter) in com.store.pets.CustomInstantDeserializer cannot override withDateFormat(org.threeten.bp.format.DateTimeFormatter) in com.fasterxml.jackson.datatype.threetenbp.deser.ThreeTenDateTimeDeserializerBase [ERROR] return type com.fasterxml.jackson.databind.JsonDeserializer<T> is not compatible with com.fasterxml.jackson.datatype.threetenbp.deser.ThreeTenDateTimeDeserializerBase<T> [ERROR] /target/generated-sources/openapi/src/gen/java/main/com/store/pets/CustomInstantDeserializer.java:[149,3] method does not override or implement a method from a supertype

Related issues/PRs

Could not find.

Suggest a fix

As a workaround, one can specify a dateLibrary explicitly in the configOptions, and the code will generate and compile.

<dateLibrary>joda</dateLibrary> or <dateLibrary>java8</dateLibrary>

delitahub avatar Feb 26 '20 04:02 delitahub

We are getting similar errors. Any one looking into this?

alexatencompass avatar May 08 '20 04:05 alexatencompass

Thanks @delitahub 👍

Adding this to the execution configuration worked for me:

<configOptions>
  <dateLibrary>java8</dateLibrary>
</configOptions>

jannik-mohemian avatar May 15 '20 08:05 jannik-mohemian

Thanks @delitahub

Adding this to the execution configuration worked for me:

<configOptions>
  <dateLibrary>java8</dateLibrary>
</configOptions>

You're welcome! :tada:

delitahub avatar May 15 '20 18:05 delitahub

We are getting similar errors. Any one looking into this?

Unfortunately, there seems to be no update from the java client generator maintainer(s). You can try the suggested workaround and see if this is enough for your case.

delitahub avatar May 15 '20 18:05 delitahub

I'd like to bump this.

https://openapi-generator.tech/docs/generators/java says that java8 is the default.

I get the same error without the workaround. Explicitly setting java8 (even if its the default) fixes it.

jkoorts avatar Aug 04 '22 13:08 jkoorts