to add my links in the Json frame of a projection I added the following class:
@Component
public class ResumeEntityProjectionResourceProcessor implements ResourceProcessor<Resource<ResumeEntity>> {
@Override
public Resource<ResumeEntity> process(Resource<ResumeEntity> resource) {
UriComponents uriComponents = ServletUriComponentsBuilder.fromCurrentContextPath()
.path("/api/entities/search/findEntities")
.buildAndExpand(Long.toString(resource.getContent().getId()));
resource.add(new Link(uriComponents.toUriString(), "findEntities"));
return resource;
}
The problem I had now as a return value was two keys "_links" one with the default links plus my links and the other with my links only.
{
"_embedded": {
"entities": [{
"id": 1696,
"reference": "aaaaaa",
"_links": {
"self": {
"href": "http://localhost:8080/myProject/api/entities/1696{?projection}",
"templated": true
},
"findByParametresValide": {
"href": "http://localhost:8080/myProject/api/entities/search/findEntities"
}
},
"_links": {
"findByParametresValide": {
"href": "http://localhost:8080/myProject/api/entities/search/findEntities"
}
}
}
]
}
}
How I did to keep only the first tag?
the expected result
{
"_embedded": {
"entities": [{
"id": 1696,
"reference": "aaaaaa",
"_links": {
"self": {
"href": "http://localhost:8080/myProject/api/entities/1696{?projection}",
"templated": true
},
"findByParametresValide": {
"href": "http://localhost:8080/myProject/api/entities/search/findEntities"
}
}
}
]
}
}
thanks