gpt4 book ai didi

java - JAXB 不编码(marshal)循环引用

转载 作者:太空宇宙 更新时间:2023-11-04 10:16:58 24 4
gpt4 key购买 nike

我之前使用过 JAXB 从循环数据结构生成 json,我想这次我做了同样的事情,但显然没有,因为我收到了这个错误:

Jul 30, 2018 4:28:08 PM org.eclipse.yasson.internal.Marshaller marshall
SEVERE: Generating incomplete JSON
Jul 30, 2018 4:28:08 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jersey-servlet] in context with path [/Kanzan] threw exception [org.glassfish.jersey.server.ContainerException: java.lang.StackOverflowError] with root cause
java.lang.StackOverflowError
at java.util.concurrent.ConcurrentHashMap$BaseIterator.<init>(ConcurrentHashMap.java:3389)
at java.util.concurrent.ConcurrentHashMap$ValueIterator.<init>(ConcurrentHashMap.java:3430)
at java.util.concurrent.ConcurrentHashMap$ValuesView.iterator(ConcurrentHashMap.java:4683)
at org.eclipse.yasson.internal.ComponentMatcher.searchComponentBinding(ComponentMatcher.java:179)
at org.eclipse.yasson.internal.ComponentMatcher.getSerializerBinding(ComponentMatcher.java:135)
at org.eclipse.yasson.internal.serializer.SerializerBuilder.build(SerializerBuilder.java:72)
at org.eclipse.yasson.internal.serializer.ObjectSerializer.marshallProperty(ObjectSerializer.java:91)
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.ObjectSerializer.marshallProperty(ObjectSerializer.java:92)
at org.eclipse.yasson.internal.serializer.ObjectSerializer.serializeInternal(ObjectSerializer.java:59)

这是来源:

@XmlAccessorType(XmlAccessType.FIELD)
@Entity
@Table(name="INTERVIEW")
public class Interview {
@Id
@GeneratedValue
@Column (name = "ID")
private int id;
@Column (name="DATE")
private Date date_;
@Column (name="TITLE")
private String title;
@Column (name="CEO")
private String ceo;
@OneToMany (mappedBy="interview", cascade = CascadeType.ALL, orphanRemoval = true)
private List<QA> QAs;
@OneToOne
@JoinColumn(name="STOCK_ID")
@XmlTransient
private Stock stock;

....GETTERS and SETTERS...
}


@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@Entity
@Table(name="STOCK")
public class Stock {
@Id
@GeneratedValue
@Column (name = "ID")
private int id;
@Column (name="TITLE")
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "stock")
private Interview interview;

....GETTERS AND SETTERS....
}

如果我从各自中删除采访和股票引用,我可以编码。

最佳答案

已解决。工作需要一些 Jersey jar

关于java - JAXB 不编码(marshal)循环引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51596606/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com