我正在与Jackson一起使用RatPack 1.1.1,它以不同的方式呈现相同的对象“Product”。我的主对象中的第一个“Product”返回属性“productCode”,但对于同一产品的其他属性,它只返回一个属性值“product”,其值为“productCode”!
为什么呢?这是正常的吗?
渲染的响应:
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",
}
]
感谢您的帮助!