Skip to content

Disabling SerializationFeature.FAIL_ON_EMPTY_BEANS does not affect canSerialize #756

@nickwongdev

Description

@nickwongdev

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions