Jackson-databind: Consider changing default setting of `FAIL_ON_EMPTY_BEANS` from true to false

Created on 3 Mar 2021  路  2Comments  路  Source: FasterXML/jackson-databind

I would expect an empty Object without any field to be rendered as {}

When I drove a Spring Boot Rest API with an Acceptance Test step by step, I tried to respond with an empty Object at one point, expecting an empty Json Object as a response.
However, Spring noticed that Jackson would not serialize this Object, and instead jumped to the next Converter which caused unrelated Issues. It took me about 1 hour of analyzing at the wrong end, to figure out the real cause.

I think it would be beneficial for developers, if the default of FAIL_ON_EMPTY_BEANS was false, and an empty Json Object would be created in that case.

3.x

Most helpful comment

Default settings changes are possible for the major version upgrade, although we'd need to figure out some way to gauge how popular change proposals are.
Marking as 3.0.

All 2 comments

Default settings changes are possible for the major version upgrade, although we'd need to figure out some way to gauge how popular change proposals are.
Marking as 3.0.

Presupposing the intention of this feature is to warn the user about potential mistakes in serialization configuration, I'd assert some arguments against a survey/proposal precluding this change:

  • This behavior is incongruous with other JSON serializers.

    • The JSON representation of an object with no properties is {}. I don't see any ambiguity there which warrants blocking the user until they confirm this is what they expect.

    • I would expect the default behavior of a serializer to produce the standard unambiguous JSON representation.

  • Use exceptions only for exceptional conditions (_Effective Java (3rd)_, Item 69). I don't think a potential configuration mistake is an exceptional condition.
Was this page helpful?
0 / 5 - 0 ratings