一.原因
当一对多One引用了More的对象,而More又引用了One,相互引用造成无限循环序列化
二.解决方法
可以使用SerializerFeature自定义序列化格式
protected String toJsonString(Object object){
SerializerFeature[] features = new SerializerFeature[]{
SerializerFeature.DisableCircularReferenceDetect,
SerializerFeature.WriteMapNullValue,
SerializerFeature.WriteNullListAsEmpty,
SerializerFeature.WriteNullStringAsEmpty,
SerializerFeature.WriteDateUseDateFormat
};
JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
String jsonStr = JSON.toJSONString(object,features);
return jsonStr;
}