spring-projects / spring-projects/spring-data-rest

Links are wrongly serialized when MappingJacksonValue is used as a return type [DATAREST-1179]

Open
#1,544 2 comments 0 reactions 1 assignee View on GitHub

@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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.