Skip to content

symfony-ux-live-component: hydrating via the NormalizerBridgePropertyHydrator #152

@johanv

Description

@johanv

While trying out symfony-ux-live-component (which is awesome btw; thank you for creating this!), I stumbled upon an issue.
The project I am experimenting with, uses a lot of value objects, and I have a decent amount of normalizers in place to normalize these value objects. Since a class NormalizerBridgePropertyHydrator exists, I thought using my value objects with the live components might work.

When I tried that, I got these kinds of error messages:

An exception has been thrown during the rendering of a template ("Cannot dehydrate property "playerIdentifier" of "App\Components\PlayerSwitchComponent". The value "App\Domain\ValueObject\Player\PlayerIdentifier" does not have a dehydrator.").

With the help of XDebug, I noticed that the NormalizerBridgePropertyHydrator was trying to use Symfony's DateTimeNormalizer to normalize/denormalize my value objects, which obviously failed.

Now I have managed to fix this by adding these lines to the services.yml file of my project:

    Symfony\UX\LiveComponent\PropertyHydratorInterface:
        class: Symfony\UX\LiveComponent\Hydrator\NormalizerBridgePropertyHydrator
        arguments:
            - '@Symfony\Component\Serializer\Normalizer\NormalizerInterface'

I'm not completely sure this is how this hydrator is intended to be used. But it seems to work for me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions