spring-projects / spring-projects/spring-hateoas
Resource JSON serialization produce empty "content" property
@odrotbohm is already working on this.
Since May 21, 2015.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 476
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
here is my controller code:
@RequestMapping(value= "/test-resource", method = RequestMethod.GET)
public TestResource test() {
return new TestResource(new Test());
}
private class TestResource extends Resource<Test> {
public TestResource(Test content, Link... links) {
super(content, links);
}
}
private class Test {}
And I use the MappingJackson2HttpMessageConverter as an ObjectMapper.
The result of requesting my controller's method is:
{
"content": {
}
}
But in case of Test class is an @Entity or a @Component, it serialized correctly:
{ }
The reason of such behaviour is that Jackson uses UnwrappingBeanSerializer to serialize @Entity and unwrap "content" property, but in case of POJO Jackson uses UnknownSerializer that serialize content as is.
The problem can be solved by setting @JsonSerialize(include = JsonSerialize.Inclusion.NON_EMPTY) class annotation on TestMixIn, but it looks like a hack.
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.