gpt4 book ai didi

java - 忽略 JSON Jackson 注释

转载 作者:搜寻专家 更新时间:2023-11-01 02:58:43 26 4
gpt4 key购买 nike

我正在使用 @JsonIgnore,但仍然收到 StackoverflowError。

有一个循环,注释被忽略。

@Entity
@NamedQuery(name="Buch.findAll", query="SELECT b FROM Buch v")
public class Buch implements Serializable {
private static final long serialVersionUID = 1L;

...

//bi-directional many-to-one association to Titel
@OneToOne(mappedBy="buch")
@JsonIgnore
private Titel Titel;

...

@JsonIgnore
public Titel getTitel() {
return this.verein;
}

@JsonIgnore
public void setTitel(Titel titel) {
this.titel= titel;
}
}

最佳答案

你的代码中有几个问题:

  • 您正在对字段及其字段使用 @JsonIgnore 注释访问器(getter 和 setter),你不应该这样做,只映射一个其中一个就足够了。我建议你只映射 getter 方法@JsonIgnore
  • 另一件事是您的 Titelgetter 方法不正确已实现,它应该返回 Titel 字段,但您正在返回this.verein,这是完全错误的,会打乱您的代码,您需要更正它。

我在这里的建议是将 @JsonIgnore 与您需要更正的 getter 方法一起使用:

@JsonIgnore
public Titel getTitel() {
return this.Titel;
}

关于java - 忽略 JSON Jackson 注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43667738/

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