json序列化级联的问题

 方法一:用JsonConfig

 

Java代码 复制代码 收藏代码
  1. import net.sf.json.JSONObject;
  2. import net.sf.json.JsonConfig;
  3. //业务类
  4. TblBaseDict dict = tblBaseDictBiz.findById(id);
  5.  
  6. JsonConfig cfg = new JsonConfig();
  7. //忽略的属性,不转json
  8. cfg.setExcludes(new String[]{"handler","hibernateLazyInitializer"});
  9. log.info(JSONObject.fromObject(dict,cfg));
  10.  
  11. JSONObject.fromObject(dict,cfg).toString();</pre>
  12. //实体类
  13. @JsonIgnoreProperties(value={"handler","hibernateLazyInitializer"})
  14. public class TblBaseDict extends BaseEntity
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
//业务类	
    	TblBaseDict dict = tblBaseDictBiz.findById(id);

    	JsonConfig cfg = new JsonConfig();   
    	//忽略的属性,不转json 
    	cfg.setExcludes(new String[]{"handler","hibernateLazyInitializer"});  
    	log.info(JSONObject.fromObject(dict,cfg));
    	
    	JSONObject.fromObject(dict,cfg).toString();</pre>
//实体类 
@JsonIgnoreProperties(value={"handler","hibernateLazyInitializer"}) 
public class TblBaseDict extends BaseEntity

 

方法二: @JsonIgnore 注解 //org.codehaus.jackson.annotate.JsonIgnore

Java代码 复制代码 收藏代码
  1. @JsonIgnore
  2. public Set<TemplateInfo> getTemplateInfos() {
  3. return templateInfos;
  4. }  

你可能感兴趣的:(的)