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-micronaut] JsonProperty missing for serializationLibrary micronaut_serde_jackson #16939

Open
frodeo opened this issue Oct 30, 2023 · 4 comments

Comments

@frodeo
Copy link

frodeo commented Oct 30, 2023

Description

When using serializationLibrary micronaut_serde_jackson the getters and setters in the generated code is missing the @JsonProperty annotation that is used for serializationLibrary jackson.

If fields in a JSON document does not use camel case notation, then it might not be possible to read the document with the JsonProperty annotation missing. The field myName is then fine, but fields like my_name, MyName, "My Name", "MY_NAME" etc will not work.

openapi-generator version

7.0.1 java-micronaut-client

OpenAPI declaration file content or url

Sample document for generating code:

openapi: 3.0.3
info:
  title: Sample API
  version: 1.0.0
paths:
  /test:
    get:
      responses:
        '200':
          description: Sample response
          content:
            application/json:
              schema:
                type: object
                properties:
                  my_name: 
                    type: string
Command line used for generation

Command-line for generating code with serializationLibrary micronaut_serde_jackson:

openapi-generator generate -i test.yaml -g java-micronaut-client -o output-serde --additional-properties=serializationLibrary=micronaut_serde_jackson

Command-line for generating code with serializationLibrary jackson:

openapi-generator generate -i test.yaml -g java-micronaut-client -o output-jackson --additional-properties=serializationLibrary=jackson
Steps to reproduce

Sample test document:

{
    "my_name": "My name"
}

It is not possible to deserialize the test document above using the Serde version of TestGet200Response since it is missing the @JsonProperty(JSON_PROPERTY_MY_NAME) annotations.

Derserialization using the Jackson versin of TestGet200Response works fine since it has the @JsonProperty(JSON_PROPERTY_MY_NAME) annotations.

Related issues/PRs
Suggest a fix/enhancement

The @JsonProperty(JSON_PROPERTY_MY_NAME) annotations needs to be added also when we are using serializationLibrary micronaut_serde_jackson.

@altro3
Copy link

altro3 commented Aug 25, 2024

@frodeo Just use official openapi generator for micronaut from here: https://github.com/micronaut-projects/micronaut-openapi

@frodeo
Copy link
Author

frodeo commented Aug 26, 2024

From what I can see https://github.com/micronaut-projects/micronaut-openapi is about generating Swagger from Java code. Get a generating Java from Swagger (contract first).

@altro3
Copy link

altro3 commented Aug 26, 2024

No, it works both ways. The generator from here has been moved to micronaut-openapi .

Spec to code
Code to spec

This generator is integrated into the micronaut openapi gradle / maven plugin. Look to guide: https://guides.micronaut.io/latest/micronaut-openapi-generator-client-gradle-java.html

@altro3
Copy link

altro3 commented Aug 26, 2024

Therefore, all problems or suggestions are described here: https://github.com/micronaut-projects/micronaut-openapi/issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants