本文介绍了与杰克逊无限递归的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Jackson 1.6.3和Hibernate方面遇到了问题。我在这里找到了这个主题:



但它没有解决问题。



我有一个Node对象来来往往的关系。即使使用@JsonManagedReference注解,在应用程序服务器的控制台上,我也可以看到引发的异常(无限递归)。



有没有其他选择?



$ b $ @ b
$ @
$公共类Node实现Serializable {

@Id
私人字符串ID;

@Column(name =x_pos)
private double x;


@Column(name =y_pos)
private double y;
$ b @OneToMany
@JoinColumn(name =source)
@JsonManagedReference(outgoingRelations)
private Set< Relation> outgoingRelations;


@OneToMany
@JoinColumn(name =target)
@JsonManagedReference(incomingRelations)
private Set< Relation> incomingRelations;




$ b @Entity
@Table(name =relations)
公共类关系实现Serializable {

@ Id
私人长ID;

@ManyToOne
@JoinColumn(name =source)
@JsonBackReference(outgoingRelations)
私有节点源;

@ManyToOne
@JoinColumn(name =target)
@JsonBackReference(incomingRelations)
私有节点目标;

问候

解决方案来自:


I'm having problems with Jackson 1.6.3 and Hibernate. I found this thread here : Infinite Recursion with Jackson JSON and Hibernate JPA issue

But it did not solve the problem.

I have a Node object that has incoming and outgoing relations. Even with the @JsonManagedReference annotations, on the console of the app server I can see the exceptions being thrown (infinite recursion).

Is there any alternative to that?

@Entity
@Table(name="nodes")
public class Node implements Serializable {

@Id
private String id;

@Column(name="x_pos")
private double x;


@Column(name="y_pos")
private double y;

@OneToMany
@JoinColumn(name="source")
@JsonManagedReference("outgoingRelations")
private Set<Relation> outgoingRelations;


@OneToMany
@JoinColumn(name="target")
@JsonManagedReference("incomingRelations")
private Set<Relation> incomingRelations;



@Entity
@Table(name="relations")
public class Relation implements Serializable {

@Id
private Long id;

@ManyToOne
@JoinColumn(name="source")
@JsonBackReference("outgoingRelations")
private Node source;

@ManyToOne
@JoinColumn(name="target")
@JsonBackReference("incomingRelations")
private Node target;

Regards

解决方案

From spring - Infinite Recursion with Jackson JSON and Hibernate JPA issue:

这篇关于与杰克逊无限递归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-21 06:04