将Java类转换为Json模式 - FasterXML / jackson-module-jsonSchema

时间:2018-03-14 15:44:31

标签: fasterxml jackson-modules

我正在使用一些Spring Boot代码将java类转换为Json模式,并且只是通过将依赖项添加到POM文件而得到奇怪的行为,如

    <dependency>
        <groupId>com.fasterxml.jackson.module</groupId>
        <artifactId>jackson-module-jsonSchema</artifactId>
        <version>2.9.4</version>
    </dependency>

我得到的错误是:

The Bean Validation API is on the classpath but no implementation could be found
Action:
Add an implementation, such as Hibernate Validator, to the classpath

有关阅读或解决的任何建议。

感谢。

1 个答案:

答案 0 :(得分:1)

是的,因为你提到的神器取决于:

<dependency>
    <groupId>javax.validation</groupId>
    <artifactId>validation-api</artifactId>
    <version>1.1.0.Final</version>
</dependency>

但这只是验证API,必须添加一个可以执行“真实”工作的真实验证器。 看到你的pom.xml会很有趣,因为许多Spring Boot Starters已经提供了验证实现,例如:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

......附带......

<dependency>
    <groupId>org.hibernate.validator</groupId>
    <artifactId>hibernate-validator-parent</artifactId>
</dependency>

顺便说一句,您所描述的行为也记录在此Spring Boot issue

将使用此pull request进行修复,只有在真正执行验证操作时才会强制执行验证(@Validated)。