jsonschema2pojo 中的 JSR-303 激活

JSR-303 activation in jsonschema2pojo

jsonschema2pojo 文档中有一个地方描述了启用 JSR-303 annotations generation 的可能性。如果我理解正确,可以通过 Maven 插件配置来完成。有人可以展示如何完成它,应该使用插件配置中的哪个标签吗?感谢大家!

我发现 place 那里描述了 Maven 插件配置标签,"includeJsr303Annotations" 应该用于我的情况。

我认为您正在寻找 includeJsr303Annotations parameter. See the plugin documentation:

includeJsr303Annotations

Whether to include JSR-303 annotations (for schema rules like minimum, maximum, etc) in generated Java types. Schema rules and the annotation they produce:

Any Java fields which are an object or array of objects will be annotated with @Valid to support validation of an entire document tree.

  • Type: boolean
  • Since: 0.3.2
  • Required: No
  • Expression: ${jsonschema2pojo.includeJsr303Annotations}
  • Default: false

可以如下使用:

<plugins>
    <plugin>
        <groupId>org.jsonschema2pojo</groupId>
        <artifactId>jsonschema2pojo-maven-plugin</artifactId>
        <version>0.4.27</version>
        <configuration>
            <sourceDirectory>${basedir}/src/main/resources/schema</sourceDirectory>
            <targetPackage>com.example.types</targetPackage>
            <includeJsr303Annotations>true</includeJsr303Annotations>
        </configuration>
        <executions>
            <execution>
                <goals>
                    <goal>generate</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
</plugins>