Java – Jackson: multiple back reference attributes named ‘defaultreference’

I tried to map a JSON (string format) to an object, and I got the following error

This is a JSON string

{"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":""}

This is the object

@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

This is the code for mapping

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

I didn't know the mistake. I did exactly what I saw on Jackson's home page Anyone who knows, please help me

Solution

If you use @ jsonbackreference more than twice in getter / setter methods in your project, you should distinguish them from specific reference names Only one "defaultreference" is allowed in the latest version

for example

In movementview class

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

In user class

@JsonManagedReference(value="user-movement")
    public User getMovementView() {
    return movementView;
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>