我已经陷入了一个问题很长一段时间了,我渴望解决它。我有一个对象,其中包含带有ID相互引用的对象,我需要将其反序列化为对象,但是在尝试这样做时,我不断得到。JacksonJSONUnresolved forward references exception
我尝试过使用上面的注释类,但这没有产生任何结果。Jackson@JsonIdentityInfo
JSON 示例:
{
"customer": [
{
"id": 1,
"name": "Jane Gallow",
"age": 16
},
{
"id": 2,
"name": "John Sharp",
"age": 20
},
],
"shoppingcart": [
{
"id": 1,
"customer": 2,
"orderDate": "2015-02-19"
}
]
}
客户类
@JsonIdentityInfo(generator= ObjectIdGenerators.PropertyGenerator.class, property="id",scope = Customer.class)
@JsonIdentityReference(alwaysAsId = true)
public class Customer {
private int id = -1;
private String name;
private int age;
//getters, setters
}
购物车类
<!-- language: java -->
@JsonIdentityInfo(generator= ObjectIdGenerators.PropertyGenerator.class, property="id",scope = ShoppingCart.class)
public class ShoppingCart {
private int id = -1;
private Customer customer;
@JsonDeserialize(using = LocalDateDeserializer.class)
@JsonSerialize(using = LocalDateSerializer.class)
private LocalDate orderDate = LocalDate.now();
//getters, setters
}
我希望给我一个对象,该对象具有对id中的对象的引用(在本例中为约翰·夏普)。但是我只是无法让它工作,当我尝试使用方法从JSON读取时,它会给我。JacksonShoppinCartCustomer2"main" com.fasterxml.jackson.databind.deser.UnresolvedForwardReferenceObjectMapper.readValue()
波斯汪
慕田峪4524236
相关分类