spring-projects / spring-projects/spring-data-rest
Links are wrongly serialized when MappingJacksonValue is used as a return type [DATAREST-1179]
Open
@odrotbohm is already working on this.
Since Dec 31, 2020.
type: bug
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
Sam Kruglov opened DATAREST-1179 and commented
Method in @RepositoryRestController:
@GetMapping(value = "users/{id}", params = "fields")
public ResponseEntity<MappingJacksonValue> getUser(@PathVariable("id") Long id,
@RequestParam(value = "fields") String fields,
HttpServletRequest request) {
Resource<User> userResource = new Resource<>(userRepository.findOne(id));
userResource.add(new Link(request.getRequestURL() + "?fields=" + fields).withSelfRel());
userResource.add(links.linkToSingleResource(userResource.getContent()).withRel("user"));
userResource.add(links.linkToSingleResource(userResource.getContent().getGroup()).withRel("group"));
MappingJacksonValue wrapper = new MappingJacksonValue(userResource);
wrapper.setFilters(new SimpleFilterProvider()
.addFilter("userFilter",
SimpleBeanPropertyFilter.filterOutAllExcept(fields.split(","))));
return ResponseEntity.ok(wrapper);
}
Accessing GET users/1?fields=firstName
{
"firstName": "John",
"links": [
{
"rel": "self",
"href": "http://localhost:8080/users/1?fields=firstName"
},
{
"rel": "user",
"href": "http://localhost:8080/users/1{?projection}"
},
{
"rel": "group",
"href": "http://localhost:8080/groups/1"
}
]
}
Expected _links instead of *links * and href to be inside rel
Affects: 2.6.9 (Ingalls SR9)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.