OpenAPITools / OpenAPITools/openapi-generator

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

Open
#5,444 5 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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 is not compatible with com.fasterxml.jackson.datatype.threetenbp.deser.ThreeTenDateTimeDeserializerBase
[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>

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the Maven plugin using the supplied OpenAPI YAML and pom.zip, then inspect the generated CustomInstantDeserializer.java and the Spring Boot dependencies. Compare the default date-library output with the joda and java8 workarounds. Done means the generated RestTemplate client compiles with the reported dependencies without requiring an explicit dateLibrary setting.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring-boot
Domain
api, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.