JSR-303 activation in jsonschema2pojo

我是研究僧i 提交于 2020-02-24 11:59:11

问题


There is a place in jsonschema2pojo documentation describing possibility to enable JSR-303 annotations generation. If I understand correctly it can be done via Maven plugin configuration. Could someone show how to accomplish it, which tag in plugin configuration should be used? Thanks to all!


回答1:


I think you are looking for the 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:

  • maximum = @DecimalMax
  • minimum = @DecimalMin
  • minItems, maxItems = @Size
  • minLength, maxLength = @Size
  • pattern = @Pattern
  • required = @NotNull

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

It can be used as following:

<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>



回答2:


I've found the place there Maven plugin configuration tags are described, "includeJsr303Annotations" should be used for my case.



来源:https://stackoverflow.com/questions/39875725/jsr-303-activation-in-jsonschema2pojo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!