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

Disabling SerializationFeature.FAIL_ON_EMPTY_BEANS does not affect canSerialize #756

Closed
nickwongdev opened this issue Apr 9, 2015 · 3 comments
Milestone

Comments

@nickwongdev
Copy link

Spring's REST Template calls this method on MappingJackson2HttpMessageConverter:

public boolean canWrite(Class<?> clazz, MediaType mediaType) {
    return (this.objectMapper.canSerialize(clazz) && canWrite(mediaType));
}

However, this fails even though I have set:

converter.getObjectMapper().disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);

And, in fact, it will serialize the payload just fine, even though it reports that it cannot:

System.out.println(converter.getObjectMapper().canSerialize(EmptyModel.class));
System.out.println(converter.getObjectMapper().writeValueAsString(em));
System.out.println(converter.getObjectMapper().canSerialize(EmptyModel.class));
false
{}
false

Also, related to bug #703 , with version 2.5.1, the result is:

false
{}
true

I haven't had time to trace down what is enabling the actual serialization to go through on writeValueAsString, but I can try to comment later on this.

@cowtowncoder
Copy link
Member

Thank you for reporting this: it does sound like a bug indeed. As #703, that should be fixed in 2.5.2 that has been released.

@cowtowncoder cowtowncoder added this to the 2.6.0 milestone Apr 24, 2015
@cowtowncoder
Copy link
Member

Fix turned out to be bit more involved than I thought, so it will only go in 2.6.0, to minimize risk of regression in a patch release.

@nickwongdev
Copy link
Author

Thanks! 👯

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

No branches or pull requests

2 participants