Skip to content

[Serializer] Serializing empty class without properties serializes to [] when preserve_empty_objects is enabled #56875

Closed
@ruudk

Description

@ruudk

Symfony version(s) affected

7.1-RC1

Description

While testing 7.1-RC1 I noticed a change in behavior.

I have a test suite that serializes all commands (for a command bus) and confirms that they can be deserialized.

There is a command that does not have any properties:

final class DoSomethingCommand {}

When this is serialized with Symfony 7.0, it produces {}.

But with Symfony 7.1-RC1 it becomes [].

How to reproduce

See above.

Possible Solution

While debugging the situation, I notice that in 7.0 the empty object gets normalized into ArrayObject (empty).
Screenshot 2024-05-22 at 09 29 47@2x

But on 7.1-RC1 it becomes an empty array.
Screenshot 2024-05-22 at 09 31 35@2x

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions