json序列化时的懒加载和无限循环问题

No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: ***************_$$_javassist_15["hibernateLazyInitializer"]) 

 

 

大概是这个错吧,发生在json返回数据的时候,实体间互相引用造成的。

总结:

class A{
    B b;                                          //一个类

    set<C> c=new HashSet<C>(0);//一个集合

 

 

@JsonManagedReference         //在B的get方法上标注

  getB(){

  ...

  }

 

@JsonBackReference                //在C的get方法上标注

 getC(){

  ...

  }

 

}

 

 

B、C类里面也根据自身引用实体的情况进行标注即可。这样一来不会报错,但是在

model A里(假设实体B有个name普通属性):

fields:['b.name','c']

 

这样b.name是能取到值得,而无法取到A的c集合。

 

而且我想直接这样fields:['b']得到b对象,然后在view里任意取b的各种属性,但是测试过不可以。

 

 

求教高手告知……………………………………

 

 

猜你喜欢

转载自weilikk.iteye.com/blog/1953169