如何修改jsonschema2pojo-maven-plugin 0.4.11的默认@JsonInclude配置
Hey there, let's figure out why your <inclusionLevel> setting isn't working with jsonschema2pojo-maven-plugin 0.4.11.
The main issue here is that the inclusionLevel parameter wasn't actually available in version 0.4.11 — it was added in later releases (around 0.5.0). So your config isn't being picked up because the plugin doesn't recognize that setting yet.
Here are two ways to fix this:
1. Upgrade the plugin version (Recommended)
Upgrading to a newer version (0.5.0 or later) will let you use the inclusionLevel parameter as you intended. Just update your plugin config like this:
<plugin> <groupId>org.jsonschema2pojo</groupId> <artifactId>jsonschema2pojo-maven-plugin</artifactId> <version>0.5.0</version> <!-- Or a newer stable version --> <configuration> <sourceDirectory>${project.basedir}/src/main/resources/schemas</sourceDirectory> <targetPackage>com.yourpackage.models</targetPackage> <annotationStyle>jackson2</annotationStyle> <!-- Ensure this is set to generate Jackson annotations --> <inclusionLevel>ALWAYS</inclusionLevel> </configuration> <executions> <execution> <goals> <goal>generate</goal> </goals> </execution> </executions> </plugin>
After upgrading, the plugin will generate classes with @JsonInclude(JsonInclude.Include.ALWAYS) as expected.
2. Use the legacy parameter for 0.4.11
If you can't upgrade the plugin for some reason, use the includeNullProperties parameter that was available in 0.4.11. Setting this to true will achieve the same effect (adding @JsonInclude(Include.ALWAYS)):
<plugin> <groupId>org.jsonschema2pojo</groupId> <artifactId>jsonschema2pojo-maven-plugin</artifactId> <version>0.4.11</version> <configuration> <sourceDirectory>${project.basedir}/src/main/resources/schemas</sourceDirectory> <targetPackage>com.yourpackage.models</targetPackage> <annotationStyle>jackson2</annotationStyle> <!-- Don't forget this! --> <includeNullProperties>true</includeNullProperties> </configuration> <executions> <execution> <goals> <goal>generate</goal> </goals> </execution> </executions> </plugin>
Just make sure you have annotationStyle set to jackson2 — without this, the plugin won't generate any Jackson @JsonInclude annotations at all.
内容的提问来源于stack exchange,提问作者Dev Gosain

