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

Change default for SerializationFeature.FAIL_ON_EMPTY_BEANS to false #3070

Closed
gregorriegler opened this issue Mar 3, 2021 · 4 comments
Closed
Labels
3.0 Issue planned for initial 3.0 release

Comments

@gregorriegler
Copy link

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.

@gregorriegler gregorriegler added the to-evaluate Issue that has been received but not yet evaluated label Mar 3, 2021
@cowtowncoder cowtowncoder added the 3.x Issues to be only tackled for Jackson 3.x, not 2.x label Mar 3, 2021
@cowtowncoder
Copy link
Member

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.

@cowtowncoder cowtowncoder removed the to-evaluate Issue that has been received but not yet evaluated label Mar 3, 2021
@cowtowncoder cowtowncoder changed the title FAIL_ON_EMPTY_BEANS true as default considered harmful Consider changing default setting of FAIL_ON_EMPTY_BEANS from true to false Mar 3, 2021
@jrieko
Copy link

jrieko commented May 18, 2021

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.

@cowtowncoder cowtowncoder changed the title Consider changing default setting of FAIL_ON_EMPTY_BEANS from true to false Change default for DeserializationFeature.FAIL_ON_EMPTY_BEANS to false Nov 30, 2024
@cowtowncoder cowtowncoder changed the title Change default for DeserializationFeature.FAIL_ON_EMPTY_BEANS to false Change default for SerializationFeature.FAIL_ON_EMPTY_BEANS to false Nov 30, 2024
@cowtowncoder cowtowncoder added 3.0 Issue planned for initial 3.0 release and removed 3.x Issues to be only tackled for Jackson 3.x, not 2.x labels Nov 30, 2024
@cowtowncoder
Copy link
Member

I will proceed with this change, so default will change for Jackson 3.

@cowtowncoder
Copy link
Member

Changed for 3.0.0-SNAPSHOT (master branch).

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

No branches or pull requests

3 participants