Skip to content

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

Open

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

  1. spring-projects-issues commented on Jan 13, 2018

    @spring-projects-issues
    Author

    Sam Kruglov commented

    I have just read this comment and rethought my view on Spring Data REST in general. This particular example is not RESTful but I still think that this JIRA is only about MappingJacksonValue (although I do not know any other use case other than with that @JsonFilter, so if there is none then the issue may be closed)

  2. ruthst00 commented on Sep 13, 2026

    @ruthst00

    @odrotbohm, submitted this PR to fix the issue.

  3. added a commit that references this issue on Sep 13, 2026
    66431e0
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