我正在尝试将子值节点提取到其父节点。但是在获取它的同时,我得到了它的两个属性,即如何修复它。
exmpale:-
orderlinerelationshipdto.java(父级)
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "RelationshipType", "ParentLine", "ChildLine" })
@JsonTypeName("OrderLineRelationship")
@JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME)
public class OrderLineRelationshipDTO {
@JsonProperty("RelationshipType")
private String relationshipType;
@JsonProperty("ParentLine")
private ParentLineDTO parentLine;
@JsonProperty("ChildLine")
private ChildLineDTO childLine;
}
parentlinedto.java(子类)
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "PrimeLineNo" })
@JsonTypeName("ParentLine")
@JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME)
public class ParentLineDTO {
@JsonProperty("PrimeLineNo")
private String primeLineNo;
}
childlinedto.java(子类)
Data
@AllArgsConstructor
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "PrimeLineNo" })
@JsonTypeName("ChildLine")
@JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME)
public class ChildLineDTO {
@JsonProperty("PrimeLineNo")
private String primeLineNo;
}
获取此->
"OrderLineRelationships": [
{
"OrderLineRelationship": {
"RelationshipType": "ADD-ON",
"ParentLine": {
"ParentLine": {
"PrimeLineNo": "1"
}
},
"ChildLine": {
"ChildLine": {
"PrimeLineNo": "2"
}
}
}
}
]
期待这个->
"OrderLineRelationships": [
{
"OrderLineRelationship": {
"RelationshipType": "ADD-ON",
"ParentLine": {
"PrimeLineNo": "1"
},
"ChildLine": {
"PrimeLineNo": "2"
}
}
}
]
有人能帮助获取没有根名称的子对象吗?这样它将从初始化它的父类中选取根名称。
暂无答案!
目前还没有任何答案,快来回答吧!