【发布时间】:2015-05-17 18:18:22
【问题描述】:
我需要从 JSON 模式文件生成 Java 类并且遇到了 jsonschema2pojo。但是,我在使用ref 关键字时遇到了“问题”。
例如,如果我使用来自http://spacetelescope.github.io/understanding-json-schema/structuring.html#extending 的以下架构:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {
"address": {
"type": "object",
"properties": {
"street_address": { "type": "string" },
"city": { "type": "string" },
"state": { "type": "string" }
},
"required": ["street_address", "city", "state"]
}
},
"type": "object",
"properties": {
"billing_address": { "$ref": "#/definitions/address" },
"shipping_address": { "$ref": "#/definitions/address" }
}
}
正如预期的那样,它生成了一个你想怎么称呼它的类,包含一个属性billingAddress 和一个属性shippingAddress。
但是,它也生成了两个单独的类BillingAddress 和ShippingAddress,尽管这两个属性都引用了address。因此,我宁愿拥有Address 类型的两个属性。
这可以通过 jsonschema2pojo 实现吗?
【问题讨论】:
标签: java json jsonschema2pojo