【发布时间】:2020-07-04 01:58:10
【问题描述】:
我有一个 04 草案格式 (http://json-schema.org/draft-04/schema#) 的 json 模式,用于定义配置。这些模式是根据使用输入动态创建的。
我需要将此 json 模式传递给只接受 kotlin 类作为参数的方法。有没有办法将此 json 架构转换为 kotlin 数据类?
基本上我想要的是类似于www.jsonschema2pojo.org 这样做的东西,但我想在方法调用中动态创建类。
示例架构:
{
"title": "Schema 1",
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"age": {
"description": "Age in years",
"type": "integer",
"minimum": 0
}
},
"required": ["firstName", "age"]
}
【问题讨论】:
-
您想在运行时基于 Json 生成一个类?
-
是的,因为我上面提到的方法接受类作为参数。
标签: kotlin jsonschema jsonschema2pojo