我使用jsonschema2pojo (通过gradle)从具有属性(在另一个类型为“object”的属性中)的外部json模式生成pojo,定义如下(字段名和值更改,但所有类型相同):
"alternativeText": {
"type": "array",
"items": [{
"type": "object",
"required": [
"code",
"language",
"value"
],
"properties": {
"code": {
"type": "integer",
"enum": [1, 2, 3, 4]
},
"language": {
"type": "string",
"enum": ["de-DE", "en-US"]
},
"value": {
"type": "string"
}
}
}],生成以下java代码:
@JsonProperty("alternativeText")
@Valid
@NotNull
private List<Object> alternativeText = new ArrayList<Object>();
@JsonIgnore
@Valid
private Map<String, Object> additionalProperties = new LinkedHashMap<String, Object>();这个接口并不理想,特别是当使用者要针对“代码”和“语言”的枚举值进行验证时。
当枚举在数组中时,我们有类似的问题,然后API生成List<Object>而不是List<SomeEnumType>。
有什么可以配置来改进生成的代码的语义吗?对于具有"enum“的其他属性(以及该事项的对象!)它的工作正常,似乎枚举数组或对象数组变得过于简化。
发布于 2022-08-06 09:34:29
您似乎意外地对项使用了(旧的)元组语法。试着替换这个:
"items": [{有了这个
"items": {项架构不应该在数组中。
https://stackoverflow.com/questions/73226110
复制相似问题