【发布时间】:2020-11-28 20:28:21
【问题描述】:
我想知道为带有“anyOf”字段的 Json 模式生成 POJO 的推荐方法是什么?
例如,给定以下 json 架构:
爱好.json{
"anyOf": [
{ "type": {"$ref": "./exercise.json" } },
{ "type": {"$ref": "./music.json" } }
]
}
练习.json
{
"type": "object"
"properties" {
"hobbyType": {"type": "string"}
"exerciseName": { "type": "string" },
"timeSpent": { "type": "number" },
"place": { "type": "string" }
}
}
音乐.json
{
"type": "object"
"properties" {
"hobbyType": {"type": "string"}
"instrument": { "type": "string" },
"timeSpent": { "type": "number" }
}
}
如何使用 Jackson 为 Hobby.java 生成 POJO?
【问题讨论】:
-
在地图内使用地图,这可能会有所帮助
-
在 anyOf 的情况下不应该也有一个鉴别器吗?
-
@SvenDöring Json Schema 是否支持鉴别器?我认为这是一个 openApi 规范。你能分享一个关于这个的文档吗?我可以知道哪个版本的 Json Schema 支持这个吗?
标签: java jackson jsonschema pojo jsonschema2pojo