In MongoDB, I have a document collection named Customer which embeds customer-defined labels. My domain objects look like this (including Lombok annotations):
@Document(collection = "Customer")
@Getter
@Setter
public class Customer {
@Id
long id;
@Field("name")
String name;
@Field("labels")
List<CustomerLabel> labels;
}
@Getter
@Setter
public class CustomerLabel {
@Id
@Field("label_id")
long labelId;
@Field("label_name")
String labelName;
}
Right now, the response to GET /customers
looks like this:
{
"_links": {
"self": {
"href": "http://localhost:8080/app/customers?page=&size=&sort="
}
},
"_embedded": {
"customers": [
{
"name": "Smith, Jones, and White",
"labels": [
{
"labelName": "General label for Smith, Jones, and White"
}
],
"_links": {
"self": {
"href": "http://localhost:8080/app/customers/285001"
}
}
}
]
},
"page": {
"size": 20,
"totalElements": 1,
"totalPages": 1,
"number": 0
}
}
I would like to "call out" the embedded labels document as a separate link relation, so that the response to GET /customers
looks more like this:
{
"_links": {
"self": {
"href": "http://localhost:8080/app/customers?page=&size=&sort="
}
},
"_embedded": {
"customers": [
{
"name": "Smith, Jones, and White",
"_links": [
{
"labels": {
"href": "http://localhost:8080/app/customers/285001/labels"
},
{
"self": {
"href": "http://localhost:8080/app/customers/285001"
}
}]
}
]
},
"page": {
"size": 20,
"totalElements": 1,
"totalPages": 1,
"number": 0
}
}
How can I do this in my application?