日期:2014-05-16  浏览次数:20363 次

json序列化级联的问题

方法一:用JsonConfig

?

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

	@JsonIgnore
	public Set<TemplateInfo> getTemplateInfos() {
		return templateInfos;
	}

?