Java 无法写入JSON和.JsonMappingException:无限递归(StackOverflowerError)错误
我在Postman中运行查询时遇到StackOverflow递归错误。以下是模型类:Java 无法写入JSON和.JsonMappingException:无限递归(StackOverflowerError)错误,java,spring,spring-boot,jpa,postman,Java,Spring,Spring Boot,Jpa,Postman,我在Postman中运行查询时遇到StackOverflow递归错误。以下是模型类: @Entity public class UserWallet { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private Long id; @NotNull private String userName; private String firstName; private St
@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<>();
当我在Postman上运行查询时,它说:无法编写JSON:Infinite递归(StackOverflowerError);嵌套异常是com.fasterxml.jackson.databind.JsonMappingException:Infinite recursion(StackOverflowerError)(通过引用链:java.util.ArrayList[0]->com.Wallet.Model.UserWallet[\“transactions\”])“如果hibernate抛出无限循环堆栈流错误,请使用@jsonIgnore属性停止序列化。然后在反序列化过程中,将忽略JSON字段,不会抛出错误,此属性将被忽略,其值将获取其类型的默认值
按照链接了解更多信息:看起来UserWallet正在获得一笔交易,这是一笔UserWallet,它再次获得一笔交易,形成一个无限循环,尝试调试呼叫,看看是否发生了这种情况。@wizdemonizer请批准回答。
@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;