我遇到了将实体转换为JSON的问题。此Object与其他实体具有@ManyToMany关系,并且没有注释正在工作(@ JsonManagedReferenced / @ JsonBackReference,@ JsonIgnore,@ JsonIgnoreProperties,@ JsonIdentityInfo)。这些适用于其他实体中的其他关系(但不是很多)。
我的第一个实体:
@Entity
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class Intervention implements Serializable {
@Id
private Integer id;
@ManyToMany(cascade = CascadeType.ALL, mappedBy = "interventionList")
private List<Employee> employeeList = new ArrayList<>();
public Intervention() {
}
// getters and setters
}
我的第二个:
@Entity
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class Employee implements Serializable {
@Id
private Integer id;
@JoinTable(name = "employee_intervention", joinColumns = {
@JoinColumn(name = "employee_id", referencedColumnName = "id")}, inverseJoinColumns = {
@JoinColumn(name = "intervention_id", referencedColumnName = "id")})
@ManyToMany
private List<Intervention> interventionList = new ArrayList<>();
public Employee() {
}
// getters and setters
}
在这里,我使用@JsonIdentityInfo,但我尝试了之前提到的所有注释。
我收到此错误:
Grave: Generating incomplete JSON
Avertissement: StandardWrapperValve[jersey-servlet]: Servlet.service() for servlet jersey-servlet threw exception
java.lang.StackOverflowError
at org.eclipse.yasson.internal.serializer.ObjectSerializer.serializeInternal(ObjectSerializer.java:59)
at org.eclipse.yasson.internal.serializer.AbstractContainerSerializer.serialize(AbstractContainerSerializer.java:60)
at org.eclipse.yasson.internal.serializer.AbstractContainerSerializer.serializerCaptor(AbstractContainerSerializer.java:91)
at org.eclipse.yasson.internal.serializer.ObjectSerializer.marshallProperty(ObjectSerializer.java:92)
at org.eclipse.yasson.internal.serializer.ObjectSerializer.serializeInternal(ObjectSerializer.java:59)
at org.eclipse.yasson.internal.serializer.AbstractContainerSerializer.serialize(AbstractContainerSerializer.java:60)
at org.eclipse.yasson.internal.serializer.AbstractContainerSerializer.serializerCaptor(AbstractContainerSerializer.java:91)
at org.eclipse.yasson.internal.serializer.CollectionSerializer.serializeInternal(CollectionSerializer.java:76)
at org.eclipse.yasson.internal.serializer.CollectionSerializer.serializeInternal(CollectionSerializer.java:35)
at org.eclipse.yasson.internal.serializer.AbstractContainerSerializer.serialize(AbstractContainerSerializer.java:60)
...
提前致谢!