方法一:用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
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;
- }
转载于:https://blog.51cto.com/shuaigee/1133489