spring-projects / spring-projects/spring-hateoas
Link affordances don't survive a Jackson serialization and deserialzation
@odrotbohm is already working on this.
Since Aug 5, 2020.
- 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
- 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.