Skip to content

Serializer decorator does not support ArrayObject as object normalization result #149

@7-zete-7

Description

@7-zete-7

When setting the preserve_empty_objects flag in a normalization context, objects normalized to empty arrays are returned from the Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize() method as ArrayObject. This is expected behavior. However, when using this flag and using this package, the following error occurs:

TypeError: array_merge(): Argument #2 must be of type array, ArrayObject given
/app/vendor/dunglas/doctrine-json-odm/src/SerializerTrait.php:59
/app/vendor/dunglas/doctrine-json-odm/src/TypedSerializerTrait.php:26
/app/vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php:227
/app/vendor/symfony/serializer/Serializer.php:152
...

As a solution to the problem, I suggest interacting with the result of object normalization as ArrayAccess, not array.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions