0

我正在使用 JsonSchema2Pojo 将 json 转换为模型对象。它按预期创建模型对象。但是,我也需要注释 @JsonIgnoreProperties(ignoreUnknown = true) 。此 JsonSchema2Pojo 无法使用此注释。但是,看起来它支持属性 includeAdditionalProperties。即使设置了这个,我在生成的类中也看不到 additionalPropertiesMap 。这里有什么遗漏吗?

            <plugin>
                <groupId>org.jsonschema2pojo</groupId>
                <artifactId>jsonschema2pojo-maven-plugin</artifactId>
                <version>0.5.1</version>
                <configuration>
                    <sourceDirectory>${project.parent.basedir}/app-service/src/main/resources/schema</sourceDirectory>
                    <targetPackage>com.xyz.test.dto</targetPackage>
                    <annotationStyle>jackson2</annotationStyle>
                    <generateBuilders>true</generateBuilders>
                    <useCommonsLang3>true</useCommonsLang3>
                    <useLongIntegers>false</useLongIntegers>
                    <includeJsr303Annotations>true</includeJsr303Annotations>                    
                    <includeAdditionalProperties>false</includeAdditionalProperties>
                </configuration>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
4

1 回答 1

1

它可以通过使用自定义注释器来完成。

示例实现和使用可在此处获得。

https://github.com/thewizardofjoz/jsonschema2pojo-ignoreunknown-annotator
https://github.com/thewizardofjoz/jsonschema2pojo-example
于 2018-09-02T11:01:40.067 回答