2 wccjava wccjava 于 2013.11.06 16:48 提问

jackson json 使用问题

有Department类
public class Department {
private Long id;
private String name;
private Department parDepartment;//上级部门

    //method set、get
   .......

}

有如下dept和dept1 2个对象,dept是dept1的上级部门
Department dept = new Department();
dept.setId(1L);
dept.setName("宜通世纪");

Department dept1 = new Department();
dept1.setId(2L);
dept1.setName("终端解决方案部");
dept1.setParDepartment(dept);

如何使用jackson的注解设置Department类,使得dept1转成json对象时是一下格式:
{"id":2,"name":"终端解决方案部","pId":1}

Csdn user default icon
上传中...
上传图片
插入图片