I'm developing a Spring Boot Application for a shopping list. For this I use Spring Data Rest to export my entities through a REST API.
My Architecture looks like this
I have a ShoppingItem:
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;
}
}
This shopping item contains an Article which is an exported Resource.
The Article looks like this:
public class Article {
@Id
@GeneratedValue
private Long id;
@Column(unique = true)
private String name;
private Integer price;
}
When i request a ShoppingItem the answer looks like this:
{
id: 94,
number: 1,
bought: false,
_links: {
self: {
href: "http://ift.tt/1DmsK9F"
},
article: {
href: "http://ift.tt/1yuX8PV"
}
}
}
Is it possible to include the Article
in _embedded when requesting the ShoppingItem
so the response looks like this?
{
id: 94,
number: 1,
bought: false,
_links: {
self: {
href: "http://ift.tt/1DmsK9F"
},
article: {
href: "http://ift.tt/1yuX8PV"
}
},
_embedded: {
article: {
id: '999',
name: 'someThing',
price: '1.99'
}
}
}
Aucun commentaire:
Enregistrer un commentaire