spring-projects / spring-projects/spring-hateoas

Link affordances don't survive a Jackson serialization and deserialzation

Open
#1,345 10 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Aug 5, 2020.

process: waiting for feedback
Dominant language
Java
Stars
1.1k
Forks
476
PR merge metrics
No merged PRs in 30d

Description

In a REST controller test I compare an object with an added self link with the result of a HTTP transport (via TestRestTemplate). The result is not equal to the original, because the deserialized link has no affordance, where the original after adding the link has one. The reason seems to be the discrepancy between the @JsonIgnore on affordances and the inclusion of this member in the equals method.
This can simply be reproduced by test case according to the following (incomplete) example:

    @Test
    public void serializeWithLink() throws JsonProcessingException {

        SomeClassWithRepresentationModel  expected =  createThisObject();
        Link selfLink = linkTo(methodOn(SomeSpringRestController.class).methodForGetRequest()).withSelfRel();
        expected.add(selfLink);

        ObjectMapper objectMapper = new ObjectMapper(); // Jackson object mapper
        String jsonSerial = objectMapper.writeValueAsString(expected);
        SomeClassWithRepresentationModel actual = objectMapper.readValue(jsonSerial, SomeClassWithRepresentationModel.class);

        Assertions.assertEquals(expected, actual);
    }

At least in my special case with a real object and a real REST controller this test fails.

Contributor guide

No contributing guide indexed for this repository

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.