本文介绍了杰克逊:名称为"defaultReference"的多个后向引用属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将json(字符串格式)映射到对象,但出现以下错误

I'm trying to map a json (string format) to an object and I get the following error

这是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);

我不知道这个错误,我做的方式与我在杰克逊首页上阅读的方式完全相同.任何人都知道的,请帮助我

I have no idea with this error, I did exact the same way as I read on Jackson homepage. Anyone who knows about it, please help me

推荐答案

如果在项目中的多个getter/setter方法上使用@JsonBackReference,则应使用特定的引用名称来区分它们.

If you use @JsonBackReference on more than one getter/setter method in your project, you should distinguish them with a specific reference name.

在最新版本中也许只允许一个'defaultReference'吗?

Maybe only one 'defaultReference' is allowed in the latest version?

例如

MovementView.java

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

User.java

@JsonManagedReference(value="user-movement")
public MovementView getMovementView() {
    return movementView;
}

这篇关于杰克逊:名称为"defaultReference"的多个后向引用属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 23:39