解决spring mvc JSON 无法转换对象为json格式 无限死循环

[color=red]控制台出现如下循环异常:[/color]

at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446)
at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
at org.codehaus.jackson.map.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:72)
at org.codehaus.jackson.map.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:23)
at org.codehaus.jackson.map.ser.std.AsArraySerializerBase.serialize(AsArraySerializerBase.java:86)
at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446)
at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446)
at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
at org.codehaus.jackson.map.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:72)
at org.codehaus.jackson.map.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:23)
at org.codehaus.jackson.map.ser.std.AsArraySerializerBase.serialize(AsArraySerializerBase.java:86)
at
org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446)
at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446)
at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
at org.codehaus.jackson.map.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:72)
at org.codehaus.jackson.map.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:23)
at org.codehaus.jackson.map.ser.std.AsArraySerializerBase.serialize(AsArraySerializerBase.java:86)
at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446)
at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446)
at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
at org.codehaus.jackson.map.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:72)
at org.codehaus.jackson.map.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:23)
at org.codehaus.jackson.map.ser.std.AsArraySerializerBase.serialize(AsArraySerializerBase.java:86)
at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446)
at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446)
at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
at org.codehaus.jackson.map.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:72)
at org.codehaus.jackson.map.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:23)
at org.codehaus.jackson.map.ser.std.AsArraySerializerBase.serialize(AsArraySerializerBase.java:86)
at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446)
at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446)
at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
at org.codehaus.jackson.map.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:72)
at org.codehaus.jackson.map.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:23)
at org.codehaus.jackson.map.ser.std.AsArraySerializerBase.serialize(AsArraySerializerBase.java:86)
at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446)
at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446)
at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
at org.codehaus.jackson.map.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:72)
at org.codehaus.jackson.map.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:23)
at org.codehaus.jackson.map.ser.std.AsArraySerializerBase.serialize(AsArraySerializerBase.java:86)
at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446)
at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446)
at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
at org.codehaus.jackson.map.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:72)
at org.codehaus.jackson.map.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:23)
at org.codehaus.jackson.map.ser.std.AsArraySerializerBase.serialize(AsArraySerializerBase.java:86)
at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446)
at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446)
at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
at org.codehaus.jackson.map.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:72)
at org.codehaus.jackson.map.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:23)
at org.codehaus.jackson.map.ser.std.AsArraySerializerBase.serialize(AsArraySerializerBase.java:86)
at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446)
at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446)
at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
at org.codehaus.jackson.map.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:72)

[color=red]今天做显示商品评论功能 使用springmvc ajax加载,查询出来的数据转换成json时出现了死循环,如下:[/color]
[quote]
[{"commentid":22,"goods":{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产","goodses":[{"goodsid":8,"goodsarea":{"areaid":3,"areaName":"毕节特产",
[/quote]
[color=red]查询评论表 而评论表和商品表是多对一的关系,商品表和分类表.地区表多对一的关系,[/color]
[color=orange]死循环原因:json无法对comments表的goods属性进行转换[/color]
[color=red]解决办法:[/color]
[color=orange]在comments实体类上加注解@JsonIgnoreProperties(value={"goods"})[/color]

@JsonIgnoreProperties(value={"goods"})
public class Comments implements java.io.Serializable {

// Fields

/**
*
*/
private static final long serialVersionUID = 6666646538881797793L;
private Integer commentid;
private Goods goods;
private User user;
private String comment;
private String time;


:D
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值