java – Jackson:多个back-reference属性,名称为’defaultReference’

前端之家收集整理的这篇文章主要介绍了java – Jackson:多个back-reference属性,名称为’defaultReference’前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图将一个json(字符串格式)映射到一个对象,我得到以下错误

com.fasterxml.jackson.databind.JsonMappingException: Multiple
back-reference properties with name ‘defaultReference’

这是json字符串

{"pledge":"74","client":"66","date":"","originId":"1","qualityId":"2","grade":"19","packing":"4","tons":"1000","fromDate":"","toDate":"","type":0,"remark":"","status":0,"area":"1531","id":-1,"refNumber":"","log":"","user":""}

这是对象

@Entity
@Table(name="movement",catalog = "wsmill3")
public class MovementView implements java.io.Serializable {
    private Integer id;
    private Integer originId;
    private Integer qualityId;
    private String refNumber;
    private Integer client;
    private String clientRef;
    private Integer grade;
    private Integer packing;
    private Integer pledge;
    private Integer area;
    private Date date;
    private Double tons;
    private Date fromDate;
    private Date toDate;
    private String remark;
    private User user;
    private Byte status;
    private String log;
    private Byte type;
    //constructor,getter and setter

这是做映射的代码

String data = request.getParameter("data");
ObjectMapper mapper = new ObjectMapper();
MovementView movement = mapper.readValue(data,MovementView.class);

我不知道这个错误,我做的确和我在杰克逊主页上看到的一样.任何知道的人,请帮助我

解决方法

如果在项目中的getter / setter方法中使用@JsonBackReference两次以上,那么您应该将它们与特定的引用名称进行区分.在最新版本中只允许使用一个“defaultReference”.

例如

在MovementView.class

@JsonBackReference(value="user-movement")
public User getUser() {
    return user;
}

在User.class

@JsonManagedReference(value="user-movement")
    public User getMovementView() {
    return movementView;
}
原文链接:https://www.f2er.com/java/121737.html

猜你在找的Java相关文章