gpt4 book ai didi

java - JSON : There is a cycle in the hierarchy

转载 作者:行者123 更新时间:2023-11-30 06:27:06 25 4
gpt4 key购买 nike

public class OrderEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="order_id")
private int orderid;

@ManyToOne
@JoinColumn(name="user_id", nullable=false)
private UserEntity user;

@OneToMany(mappedBy="ordersBid",fetch=FetchType.EAGER)
private Set<BidPriceEntity> bidOrders;
}
public class BidPriceEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;

@ManyToOne
@JoinColumn(name="order_Id",nullable=false)
private OrderEntity ordersBid;

@ManyToOne
@JoinColumn(name="driver_Id",nullable=false)
private UserEntity driver;

@Column(name="bid_price")
private double bidPrice;
}
public class OrderEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="order_id")
private int orderid;

@ManyToOne
@JoinColumn(name="user_id", nullable=false)
private UserEntity user;

@OneToMany(mappedBy="ordersBid",fetch=FetchType.EAGER)
private Set<BidPriceEntity> bidOrders;
}

这是三个实体。我试图将数据(从数据库检索)传输到 JsonArray。它总是收到错误:层次结构中存在循环!

我应该如何设置:JsonConfig(setJsonPropertyFilter)属性来获取消除这个错误。

最佳答案

基本上有两个循环选项 - 编写自己的序列化器,使用@JsonIgnore。就像在您的代码中一样 - OrderEntity 包含 BidPriceEntities 列表,该列表又包含对 OrderEntity 的引用。用 @JsonIgnore 标记 ordersBid ,它应该可以工作。在列表序列化...如果您无权访问该类 - 尝试 mixins

关于java - JSON : There is a cycle in the hierarchy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46968555/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com