Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource JSON serialization produce empty "content" property #277

Open
vltsu opened this issue Dec 30, 2014 · 1 comment
Open

Resource JSON serialization produce empty "content" property #277

vltsu opened this issue Dec 30, 2014 · 1 comment

Comments

@vltsu
Copy link

vltsu commented Dec 30, 2014

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.

@odrotbohm
Copy link
Member

Any chance you provide a test case that shows what exactly is failing? I get a bit lost in "Test class" and @entity and serializers you all mention but can't really wrap my hand around.

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

No branches or pull requests

2 participants