Skip to content

Change default for SerializationFeature.FAIL_ON_EMPTY_BEANS to false #3070

Closed

Description

@gregorriegler

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.

Activity

  1. added
    to-evaluate
    on Mar 3, 2021
  2. added
    3.x
    on Mar 3, 2021
  3. cowtowncoder commented on Mar 3, 2021

    @cowtowncoder
    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.

  4. removed
    to-evaluate
    on Mar 3, 2021
  5. 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[/+] on Mar 3, 2021
  6. jrieko commented on May 18, 2021

    @jrieko

    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.
  7. 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`[/+] on Nov 30, 2024
  8. changed the title [-]Change default for `DeserializationFeature.FAIL_ON_EMPTY_BEANS` to `false`[/-] [+]Change default for `SerializationFeature.FAIL_ON_EMPTY_BEANS` to `false`[/+] on Nov 30, 2024
  9. added
    3.0
    and removed
    3.x
    on Nov 30, 2024
  10. cowtowncoder commented on Nov 30, 2024

    @cowtowncoder
    Member

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

  11. added 2 commits that reference this issue on Dec 1, 2024
    a3bade9
    bacc38e
  12. cowtowncoder commented on Dec 1, 2024

    @cowtowncoder
    Member

    Changed for 3.0.0-SNAPSHOT (master branch).

  13. added
    3.0-release-notes
    on Apr 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.03.0-release-notes

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions