Spring Data Rest: incluye recursos anidados en _embedded
Estoy desarrollando una aplicación Spring Boot para una lista de compras. Para esto utilizo Spring Data Rest para exportar mis entidades a través de una API REST.
Mi arquitectura se ve así
tengo unShoppingItem:
public class ShoppingItem {
@Id
@GeneratedValue
private Long id;
@ManyToOne
@JoinColumn(name = "articleId", nullable = false)
private Article article;
private Integer number;
private boolean bought;
public ShoppingItem(){
this.article = null;
this.number = 0;
this.bought = false;
}
}
Este artículo de compra contiene un artículo que es un recurso exportado.
losArtículo Se ve como esto:
public class Article {
@Id
@GeneratedValue
private Long id;
@Column(unique = true)
private String name;
private Integer price;
}
Cuando solicito un ShoppingItem, la respuesta se ve así:
{
id: 94,
number: 1,
bought: false,
_links: {
self: {
href: "https://myDomain.tld/api/shoppingItems/94"
},
article: {
href: "https://myDomain.tld/api/shoppingItems/94/article"
}
}
}
¿Es posible incluir elArticle
en _embedded cuando solicita elShoppingItem
entonces la respuesta se ve así?
{
id: 94,
number: 1,
bought: false,
_links: {
self: {
href: "https://myDomain.tld/api/shoppingItems/94"
},
article: {
href: "https://myDomain.tld/api/shoppingItems/94/article"
}
},
_embedded: {
article: {
id: '999',
name: 'someThing',
price: '1.99'
}
}
}
actualización 1 Cuando usasAccept: application/x-spring-data-verbose+json
La respuesta se ve así:
{
id: 94
number: 1
bought: false
links: [2]
0: {
rel: "self"
href: "https://wg.yannic-klem.de/api/shoppingItems/94"
}-
1: {
rel: "article"
href: "https://wg.yannic-klem.de/api/shoppingItems/94/article"
}-
-
content: [0]
}
La lista de contenido siempre está vacía :(
actualización 2:
Para obtener más información sobre mi arquitectura, no dude en echar un vistazo a mi repositorio de Github:https://github.com/Yannic92/ShoppingList/tree/master/src/main/java/de/klem/shopping