无法写入 JSON 和 .JsonMappingException: Infinite recursion (Stack



我在邮递员中运行查询时遇到堆栈溢出递归错误。这是模型类:


@Entity
public class UserWallet {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
@NotNull
private String userName;
private String firstName;
private String lastName;
private String email;
@Temporal(TemporalType.DATE)
private Date createdDate;
@OneToMany(mappedBy = "userAccount", fetch = FetchType.EAGER)
private Set <Transaction> transactions = new HashSet<>();

事务的模型类:


@Entity
public class Transaction {
@Id
@GeneratedValue
private Long id;
private BigDecimal amount;
private java.util.Date transactionDate;
private Long  transactionReference;
private String details;
@ManyToOne
private UserWallet userAccount;

当我在Postman上运行查询时,它说:无法写入JSON:无限递归(StackOverflowError(;嵌套异常是com.fasterxml.jackson.databind.JsonMappingException:无限递归(StackOverflowError((通过引用链:java.util.ArrayList[0]->com。Wallet.Model.UserWallet[\"transactions\"](".

如果休眠引发无限循环堆栈流错误,请使用@jsonIgnore属性停止序列化。然后在反序列化中将忽略JSON字段并且不会抛出任何错误,此属性将被忽略,其值将获取其类型的默认值。

点击链接了解更多信息:动态忽略Java对象中的字段,同时从Spring MVC作为JSON发送

最新更新