我将 RatPack 1.1.1 与 Jackson 一起使用,它以不同的方式呈现相同的对象“Product”。我的主对象中的第一个“产品”返回属性“产品代码”,但对于同一产品的其他产品,它只返回一个属性值“产品”和“产品代码”的值!
为什么?正常吗?
渲染响应:
ProductCharacteristics=[ {
"id" : 1,
"product" : {
"productCode" : "cold-brew"
},
"attributeCode" : "family",
"attributeValue" : "Kits",
}, {
"id" : 2,
"product" : "cold-brew",
"attributeCode" : "Couleur",
"attributeValue" : "Noir",
}, {
"id" : 3,
"product" : "cold-brew",
"attributeCode" : "Matériaux",
"attributeValue" : "Verre-Plastique",
}
]
我的实体 ProductCharacteristic 的定义:
@Entity
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
@ToString
class ProductCharacteristic {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;
@JoinColumn(name = "product_code")
@ManyToOne(optional = false, fetch = FetchType.EAGER, cascade = CascadeType.MERGE)
Product product;
}
我的实体产品的定义:
@Entity
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="productCode")
@ToString
public class Product {
@Id
String productCode;
}
为什么响应不是这样:
ProductCharacteristics=[ {
"id" : 1,
"product" : {
"productCode" : "cold-brew"
},
"attributeCode" : "family",
"attributeValue" : "Kits",
}, {
"id" : 2,
"product" : {
"productCode" : "cold-brew"
},
"attributeCode" : "Couleur",
"attributeValue" : "Noir",
}, {
"id" : 3,
"product" : {
"productCode" : "cold-brew"
},
"attributeCode" : "Matériaux",
"attributeValue" : "Verre-Plastique",
}
]
谢谢你的帮助!