Spring REST API 中的 Json 模式验证 [英] Json schema validation in Spring REST APIs

查看:90
本文介绍了Spring REST API 中的 Json 模式验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Spring Boot 和 [jackson-module-jsonSchema] (https 构建 REST API://github.com/FasterXML/jackson-module-jsonSchema) 用于 JSON 模式生成.我正在寻找根据为公开资源定义的已定义 JSON 模式验证到达我的 API 端点(Spring 控制器)的请求 JSON 有效负载的最佳方法,验证包括检查必需字段、格式、最小值和最大值等.一切我们可以根据架构进行验证.

I’m building a REST API using Spring Boot and [jackson-module-jsonSchema] (https://github.com/FasterXML/jackson-module-jsonSchema) for JSON schema generation. I’m looking the best way to validate the request JSON payload arriving to my APIs endpoints (Spring controllers) against the defined JSON schema defined for the exposed resource, validation includes check required fields , format , min and max values, etc.. everything we can validate against the schema.

似乎 jackson json 模式模块对模式生成很有用,但对验证无效,对吗?关于如何实现我想要做的事情有什么建议吗?

Seems jackson json schema module is useful for schema generation but not for validation, am I right? Any suggestion on how to achieve what I’m trying to do?

推荐答案

如果你看看 JSON schema站点,Java 中只有两个用于验证的库.

If you take a look at JSON schema site, there are only two libraries for validation in Java.

  1. Jorge Campos 建议的 ont 已经成熟,但正在寻找新的维护者:https://github.com/fge/json-schema-validator
  2. 第二个相对较新:http://github.com/everit-org/json-架构

我最近遇到了一种情况,我不得不选择其中一个,而我选择了第一个选项.Rest Assured 库也正在使用它.

I was recently in situation where I had to choose one or the other and I picked first option. It is being used also by Rest Assured library under the hood.

这篇关于Spring REST API 中的 Json 模式验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆