【发布时间】:2021-08-20 11:45:24
【问题描述】:
假设我有以下 JSON 架构:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/product.schema.json",
"title": "Draft JSON Schema",
"type": "object",
"properties": {
"person": {
"type": "object",
"properties": {
"details": {
"type": "object",
"properties": {
"first_name": {
"type": "string"
},
"last_name": {
"type": "string"
},
"groups": {
"type": "array",
"items": { "$ref": "#/$defs/existing_groups"
}
}
}
}
},
"$defs": {
"existing_groups": [ "Teachers", "Students" ]
},
"book": {
"type": "object",
"properties": {
"title": {
"type": "string"
},
"author": {
"type": "string"
}
}
}
}
}
从这个架构中,我想在定义的深度检索可用的属性和值:
- 所以给出的是例如
person.details我希望first_name, last_name, groups被退回。 - 如果给定
person.details.groups,则应返回可能的值Student, Teacher。 - 如果给定
book.title,则应返回一个空的Array或Set。
显然您可以使用JsonPath 从JSON 对象中获取属性值,但我更希望从com.networknt.schema.JsonSchema 中获取可能的属性(以及它们的可能值,如果有的话)。
在 Java 中最简单的方法是什么?
【问题讨论】:
标签: java json jsonschema