两种简单的解决方式:
fastjson
@JSONField(serialize=false)
@OneToMany(cascade = CascadeType.ALL,
targetEntity=TDepartment.class,
fetch = FetchType.LAZY, mappedBy = "pdemartnemt")
public List<TDepartment> getDeparts() {
return departs;
}
Gson
@JSON(serialize=false)
@OneToMany(cascade = CascadeType.ALL,
targetEntity=TDepartment.class,
fetch = FetchType.LAZY, mappedBy = "pdemartnemt")
public List<TDepartment> getDeparts() {
return departs;
}
jsonConfig
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setIgnoreDefaultExcludes(false); //设置默认忽略
jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);//设置循环策略为忽略
jsonConfig.setExcludes(new String[] {"staffs"});//将所需忽略字段加到数组中