You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改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:

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:28:36