数组未生成 List<ComplexType> 但 List<Object>
Arrays are not being generated List<ComplexType> but List<Object>
我有一个复杂的架构,我正在为其生成 POJO。但是,我注意到复杂类型不会为类型 array
内的项目生成,尽管它们被标记为类型 object
。我用非常简单的模式做了一个快速测试
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"javaType": "com.walmart.services.tesseract.service.request.models.inkiru.PaymentHead",
"properties": {
"payments": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"paymentHandle": {
"type": "string"
},
"txndate ": {
"type": "string"
},
"ordernumber": {
"type": "string"
},
"stgOrderNumber": {
"type": "string"
}
}
}
]
}
}
}
这会生成以下 POJO
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"payments"
})
public class PaymentHead {
@JsonProperty("payments")
private List<Object> payments = new ArrayList<Object>();
@JsonProperty("payments")
public List<Object> getPayments() {
return payments;
}
@JsonProperty("payments")
public void setPayments(List<Object> payments) {
this.payments = payments;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(PaymentHead.class.getName()).append('@').append(Integer.toHexString(System.identityHashCode(this))).append('[');
sb.append("payments");
sb.append('=');
sb.append(((this.payments == null)?"<null>":this.payments));
sb.append(',');
if (sb.charAt((sb.length()- 1)) == ',') {
sb.setCharAt((sb.length()- 1), ']');
} else {
sb.append(']');
}
return sb.toString();
}
}
但是,它应该是 complexType 而不是 Object。不是吗?我错过了什么吗?
正确的模式应该是。请注意,items 是模式中的对象,而不是数组。
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"javaType": "com.walmart.services.tesseract.service.request.models.inkiru.PaymentHead",
"properties": {
"payments": {
"type": "array",
"items":
{
"type": "object",
"properties": {
"paymentHandle": {
"type": "string"
},
"txndate ": {
"type": "string"
},
"ordernumber": {
"type": "string"
},
"stgOrderNumber": {
"type": "string"
}
}
}
}
}
}
我有一个复杂的架构,我正在为其生成 POJO。但是,我注意到复杂类型不会为类型 array
内的项目生成,尽管它们被标记为类型 object
。我用非常简单的模式做了一个快速测试
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"javaType": "com.walmart.services.tesseract.service.request.models.inkiru.PaymentHead",
"properties": {
"payments": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"paymentHandle": {
"type": "string"
},
"txndate ": {
"type": "string"
},
"ordernumber": {
"type": "string"
},
"stgOrderNumber": {
"type": "string"
}
}
}
]
}
}
}
这会生成以下 POJO
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"payments"
})
public class PaymentHead {
@JsonProperty("payments")
private List<Object> payments = new ArrayList<Object>();
@JsonProperty("payments")
public List<Object> getPayments() {
return payments;
}
@JsonProperty("payments")
public void setPayments(List<Object> payments) {
this.payments = payments;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(PaymentHead.class.getName()).append('@').append(Integer.toHexString(System.identityHashCode(this))).append('[');
sb.append("payments");
sb.append('=');
sb.append(((this.payments == null)?"<null>":this.payments));
sb.append(',');
if (sb.charAt((sb.length()- 1)) == ',') {
sb.setCharAt((sb.length()- 1), ']');
} else {
sb.append(']');
}
return sb.toString();
}
}
但是,它应该是 complexType 而不是 Object。不是吗?我错过了什么吗?
正确的模式应该是。请注意,items 是模式中的对象,而不是数组。
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"javaType": "com.walmart.services.tesseract.service.request.models.inkiru.PaymentHead",
"properties": {
"payments": {
"type": "array",
"items":
{
"type": "object",
"properties": {
"paymentHandle": {
"type": "string"
},
"txndate ": {
"type": "string"
},
"ordernumber": {
"type": "string"
},
"stgOrderNumber": {
"type": "string"
}
}
}
}
}
}