[java-micronaut] JsonProperty missing for serializationLibrary micronaut_serde_jackson
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.
@frodeo Just use official openapi generator for micronaut from here: https://github.com/micronaut-projects/micronaut-openapi
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).
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
Therefore, all problems or suggestions are described here: https://github.com/micronaut-projects/micronaut-openapi/issues