JSON
我已经映射了我以格式发送到服务的实体。这是我的实体
@Entity
@Table(name = "company")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class Company implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@Column
private String name;
@OneToMany(mappedBy = "company")
@Cascade(value = CascadeType.ALL)
private Collection<Employee> employees;
我的员工班
@Entity
@Table(name = "employee")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class Employee implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Integer id;
@Column
String name;
@ManyToOne()
@Cascade(value = org.hibernate.annotations.CascadeType.ALL)
@JoinColumn(name = "company_id", referencedColumnName = "id")
private Company company;
但我得到不合适的 json 格式。
{
"id": 1,
"name": "Tim",
"company": {
"id": 1,
"name": "Microsoft",
"employees": [1, {
"id": 5,
"name": "Jack",
"company": 1
}, {
"id": 6,
"name": "Jack",
"company": 1
}, {
"id": 7,
"name": "Jack",
"company": 1
}, {
"id": 8,
"name": "Tommy",
"company": 1
}]
}
}
但就像我说的,我不需要“公司”中的“员工”对象。如何在我的JSON
文件中排除它?