我正在使用泽西和杰克逊创建一个网络应用程序。我已经做出了以下类型的回复POJO:
@JsonInclude(Include.NON_NULL)
public class ResponsePojo {
private Integer id;
private String name;
private String imageUrl;
private JsonObject queryParams;
public ResponsePojo(Integer id, String name, String imageUrl, JsonObject queryParams) {
this.id = id;
this.name = name;
this.imageUrl = imageUrl;
this.queryParams = queryParams;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getImageUrl() {
return imageUrl;
}
public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}
public JsonObject getQueryParams() {
return queryParams;
}
public void setQueryParams(JsonObject queryParams) {
this.queryParams = queryParams;
}
}
当我省略private JsonObject queryParams;
字段时,我从webAPI收到了正确的JSON响应。如何从响应POJO中返回JSON?
我收到以下错误:
Direct self-reference leading to cycle (through reference chain: my.package.Response["list"]->java.util.ArrayList[0]->my.package.ResponsePojo["queryParams"]->com.google.gson.JsonObject["asJsonObject"])