我正在将Spring Data Rest与JPA Repository以及我的实体(客户)与其他实体(包括其自身)的关联一起使用。下面的示例是一个自引用关联,尽管我也看到了其他关联的相同行为。
我希望在请求客户资源时
/ api / customer / 12345
响应JSON将“仅”具有到关联资源的链接,但是我看到关联资源也被反序列化为“ _embedded”
“ _ embedded”反序列化是默认行为还是我配置错误?
@RepositoryRestResource(path = "customer")
public interface CustomerRepository extends PagingAndSortingRepository<Customer, String> {
@RestResource
Optional<Customer> findById(String id);
}
@Entity
@Table(name = "CUSTOMER")
@Data
@JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
@JsonInclude(Include.NON_NULL)
public class Customer implements Serializable {
@Id
private String customerid;
private String name;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "REFERENCE_CUSTOMER")
private Customer referenceCustomer;
}
localhost:8080 / api / customer / 12345
{
name : "N12345",
_embedded : {
referenceCustomer : {
name : "R787657"
}
},
"_links": {
"self": {
"href": "http://localhost:8080/api/customer/12345"
},
"customer": {
"href": "http://localhost:8080/api/customer/12345"
},
"referenceCustomer": {
"href": "http://localhost:8080/api/customer/12345/referenceCustomer"
}
}
}