Skip to content

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

Description

@spring-projects-issues

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions