Java 如何解析无限递归(org.codehaus.jackson.map.JsonMappingException)
当我从用户调用findById方法时,会收到一个结果,但是当我尝试转换webservice的返回时,会引发此异常: org.codehaus.jackson.map.JsonMappingException:无限递归(StackOverflowerr)(通过引用链:com.empsys.user.user[“locations”]->org.hibernate.collection.internal.PersistentBag[0]->com.empsys.contact.details.Location[“contact”]->com.empsys.user.user[“locations”]->org.hibernate.collection.internal.PersistentBag[0]->com.empsys.contact.details.Location[“contact”]->com.empsys.user.user[“locations”]->org.hibernate.collection.internal.PersistentBag[0]->com.empsys.contact.details.Location[“contact”]->com.empsys.user.user[“locations”]->org.hibernate.collection.internal.PersistentBag[0]->.com.empsys.contact.details.Location[“contact”] 班级关系是: 类联系人-创建此类是为了表示系统上的多种类型的联系人Java 如何解析无限递归(org.codehaus.jackson.map.JsonMappingException),java,json,hibernate,jackson,Java,Json,Hibernate,Jackson,当我从用户调用findById方法时,会收到一个结果,但是当我尝试转换webservice的返回时,会引发此异常: org.codehaus.jackson.map.JsonMappingException:无限递归(StackOverflowerr)(通过引用链:com.empsys.user.user[“locations”]->org.hibernate.collection.internal.PersistentBag[0]->com.empsys.contact.details.Loc
@Entity
@Table(name = "CONTACT", uniqueConstraints = {@UniqueConstraint(columnNames = {"id"})})
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "CONTACT_TYPE")
public class Contact implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy="contact")
@Column(nullable = true)
@JsonManagedReference
private List<Location> locations;
...
类位置-创建此类是为了表示系统的用户和其他联系人的地址
@Entity
@Table(name = "LOCATION", uniqueConstraints = {@UniqueConstraint(columnNames = {"id"})})
public class Location implements Serializable {
@ManyToOne
@JoinColumn(name = "contact_id", nullable = false)
@JsonBackReference
private Contact contact;
...
使用的依赖项:
- (com.sun.jersey)jersey json:Version1.18
- (com.fasterxml.jackson.datatype)jackson-datatype-hibernate4:版本: 2.4.0
有人能帮我吗?我遇到过类似的问题。在我的例子中,我在创建响应JSON时不希望导航的属性上使用@JsonIgnore。我知道这是一篇非常古老的帖子,但对于将来来到这里的人来说,也许你应该看看
从Jackson 1.6开始,您可以使用。我需要在该属性中导航的可能副本,尽管如此,我尝试使用@JsonIgnore向前推进,但异常仍然发生。
@Entity
@Table(name = "LOCATION", uniqueConstraints = {@UniqueConstraint(columnNames = {"id"})})
public class Location implements Serializable {
@ManyToOne
@JoinColumn(name = "contact_id", nullable = false)
@JsonBackReference
private Contact contact;
...