I am using openapi-generator-maven-plugin to generate model sources. With my current configuration it generates methods called fromJson and toJson for every model class.
Is there a way to configure the plugin, so it won't generate this Json methods? I don't need them and they bring dependencies that I don't want in my project.
Here is my current config of the plugin
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>6.3.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/api.yaml</inputSpec>
<generatorName>java</generatorName>
<language>Java</language>
<output>${project.build.directory}/generated-sources/swagger</output>
<configOptions>
<sourceFolder>src/gen/java/main</sourceFolder>
<!-- Add custom annotation for model sources to achieve builder pattern -->
<additionalModelTypeAnnotations>@lombok.experimental.SuperBuilder @lombok.AllArgsConstructor</additionalModelTypeAnnotations>
</configOptions>
<modelPackage>my.package</modelPackage>
<!-- Only generate the model since we need it for deserialization -->
<generateApis>false</generateApis>
<generateApiDocumentation>false</generateApiDocumentation>
<generateApiTests>false</generateApiTests>
<generateModelDocumentation>false</generateModelDocumentation>
<generateModelTests>false</generateModelTests>
<generateSupportingFiles>false</generateSupportingFiles>
<generateModels>true</generateModels>
</configuration>
</execution>
</executions>
</plugin>
The fromJson and toJson methods are generated when the Java generator library is set to okhttp-gson or retrof. If not defined, the openapi-generator uses okhttp-gson by default.
You can view the different JSON processors used by examining the library config options. The majority of them use Jackson, but the default one uses gson. You can also set your serializationLibrary to jackson, but this will only effect some library generators; not all.
So, if you set your library to whichever is appropriate to your project, the unwanted toJson and fromJson methods will disappear, as will the unwanted dependencies.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With