Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Serializer] SerializedPath option not working on non-scalar types, which are serialized into scalar (eg. DateTime) #49494

Closed
@HonzaMatosik

Description

@HonzaMatosik

Symfony version(s) affected

6.2.0

Description

If SerializedPath is set on non-scalar types, eg. DateTimeImmutable:

final class ObjectDummyWithContextAttributeAndSerializedPath
{
    public function __construct(
        #[Context([DateTimeNormalizer::FORMAT_KEY => 'm-d-Y'])]
        #[SerializedPath('[property][with_path]')]
        public \DateTimeImmutable $propertyWithPath,
    ) {
    }
}

Normalization fails with error:

Symfony\Component\Serializer\Exception\LogicException: The element you are trying to set is already populated: "[property][with_path]"

But DateTimeImmutable is serialized into string, so expected result is:

['property' => ['with_path' => '02-22-2023']

How to reproduce

I created unit test for this case, which should be sufficient for reproducing: HonzaMatosik@51f1969

Possible Solution

No response

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