jackson java转json hibernate 造成的堆栈溢出 无限递归问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/bitree1/article/details/64128051

controller 返回 geometry 字段报错

Infinite recursion (*Error) 

(through reference chain: com.vividsolutions.jts.geom.Polygon["envelope"]->

com.vividsolutions.jts.geom.Polygon["envelope"]->com.vividsolutions.jts.geom.Polygon["envelope"]->
com.vividsolutions.jts.geom.Polygon["envelope"]->com.vividsolutions.jts.geom.Polygon["envelope"]->
com.vividsolutions.jts.geom.Polygon["envelope"]->com.vividsolutions.jts.geom.Polygon["envelope"]->
->com.vividsolutions.jts.geom.Polygon["envelope"]->com.vividsolutions.jts.geom.Polygon["envelope"]-
>com.vividsolutions.jts.geom.Polygon["envelope"]->com.vividsolutions.jts.geom.Polygo
n["envelope"]->com.vividsolutions.jts.geom.Polygon["envelope"]->com.vividsolutions.jts.geom.Polygon["envelope"]->com.vividsolutions.jts.geom.Polygon
["envelope"]->com.vividsolutions.jts.geom.Polygon["envelope"]->com.vividsolutions.jts.geom.Polygon["envelope"]->com.vividsolutions.jts.geom.Polygon
["envelope"]->com.vividsolutions.jts.geom.Polygon["envelope"]->com.vividsolutions.jts.geom.Polygon["envelope"]->com.vividsolutions.jts.geom.Polygon["envelope
"]->com.vividsolutions.jts.geom.Polygon["envelope"]->com.vividsolutions.jts.geom.Polygon["envelope"]->com.vividsolutions.jts.geom.Polygon["envelope"]->com.vividsol
utions.jts.geom.Polygon["envelope"]->com.vividsolutions.jts.geom.Polygon["envelope"]->com.vividsolutions.jts.geom.Polygon["envelope"]->
com.vividsolutions.jts.geom.Polygon["envelope"]->com.vividsolutions.jts.geom.Polygon["envelope"]->com.vividsolutions.jts.geom.Polygon["envelope"]->
com.vividsolutions.jts.geom.Polygon["envelope"]->com.vividsolutions.jts.geom.Polygon["envelope"]->com.vividsolutions.jts.geom.Polygon["envelope"]->
com.vividsolutions.jts.geom.Polygon["envelope"]->com.vividsolutions.jts.geom.Polygon["envelope"]->com.vividsolutions.jts.geom.Polygon["envelope"]->
com.vividsolutions.jts.geom.Polygon["envelope"]->com.vividsolutions.jts.geom.Polygon["envelope"]->com.vividsolutions.jts.geom.Polygon["envelope"]->
com.vividsolutions.jts.geom.Polygon["envelope"]->com.vividsolutions.jts.geom.Polygon["envelope"]->com.vividsolutions.jts.geom.Polygon["envelope"]->
三月 19, 2017 2:27:06 下午 org.apache.catalina.core.ApplicationDispatcher invoke
@JsonIgnore
@JSONField(serialize=false,deserialize=false)
@Type(type = "org.hibernate.spatial.GeometryType")
@Column(name = "Shape",columnDefinition="Geometry")
private Polygon Shape;
/**
* Shape()
* wkt格式
*/
@Transient
private String wktShape;
@JsonIgnore
public Polygon getShape() {
return Shape;
}
@JsonIgnore
public void setShape(Polygon shape) {
Shape = shape;
}
public String getWktShape() {
return Shape.toText();
}
public void setWktShape(String wktShape) {
this.wktShape = wktShape;
}
  注 :(1)get set 方法上面的 @JsonIgnore用于返回大写字母的字段,防止被转小写,可与字段上面的@JsonProperty组合

WARN  o.s.w.s.h.SimpleMappingExceptionResolver - Handler execution resulted in exception: Could not write content:

严重: Servlet.service() for servlet jsp threw exception

原因:jackson java转json hibernate  造成的堆栈溢出 无限递归问题

解决方法

思路:屏蔽geometry 字段输出,重新定义一个字段获取 上一个geometry字段的wkt格式字符串

代码:如我需要输出shape字段为geometry格式 

    (1)则在弄一个wktShape字段作为代替输出

    (2)字段上面的@JsonIgnorey用于前端返回json的时候屏蔽输出字段




上一篇:js 兼容问题 SELECT OPTION


下一篇:jquery.form.js失效问题。