admin管理员组文章数量:1312783
Process JSON files containing $ref references that may point to local definitions or external files.
Resolve all references recursively, ensuring every $ref points to an existing definition.
Keep $ref references intact instead of replacing them with full object data.
If a reference points to an external file (e.g., "references.json"), that file should also be processed recursively.
Generate a _validated.json output where all necessary definitions are placed inside $defs.
Example Input: main_request_original.json
{
"$schema": ";,
"title": "Main Schema",
"type": "object",
"properties": {
"localReference": { "$ref": "#/$defs/Person" },
"fileReference": { "$ref": "references.json" },
"fileSubReference": { "$ref": "references.json#/definitions/Address" }
},
"$defs": {
"Person": {
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "integer" }
}
}
}
}
Example Input: references.json
{
"definitions": {
"Address": {
"type": "object",
"properties": {
"street": { "type": "string" },
"city": { "type": "string" }
}
},
"User": {
"type": "object",
"properties": {
"id": { "type": "integer" },
"contact": { "$ref": "#/definitions/Address" }
}
}
}
}
Expected Output: main_request_original_validated.json
{
"$schema": ";,
"title": "Main Schema",
"type": "object",
"properties": {
"localReference": { "$ref": "#/$defs/Person" },
"fileReference": { "$ref": "references.json" },
"fileSubReference": { "$ref": "#/$defs/Address" }
},
"$defs": {
"Person": {
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "integer" }
}
},
"Address": {
"type": "object",
"properties": {
"street": { "type": "string" },
"city": { "type": "string" }
}
},
"User": {
"type": "object",
"properties": {
"id": { "type": "integer" },
"contact": { "$ref": "#/$defs/Address" }
}
}
}
}
As you can see the expected output should look something like above. I am having a hard time figuring out exactly how to get to this point. I am using Jackson for traversing the json.
I thought this task would be much simpler than it is turning out to be. I want to know if this feasible and if there is an easier way to go about this?
本文标签: Resolving ref References in JSON Using Kotlin and JacksonStack Overflow
版权声明:本文标题:Resolving $ref References in JSON Using Kotlin and Jackson - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741894086a2403472.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论