Skip to content

Conversation

gehrisandro
Copy link

@gehrisandro gehrisandro commented May 22, 2025

Edit: Support for union types added

This PR enhances the SelfSerializingNormalizer to support deserializing of properties which are a union type or a type of interface extending SerializedByVerbs.

Before, it was not possible to (de)serialize the following events:

class EventWithInterfaceType extends Event
{
    public function __construct(
        public DataInterface $data,
    ) {}
}

// or

class EventWithUnionType extends Event
{
    public function __construct(
        public StringData|NumberData $data,
    ) {}
}

As context, the interface and DTO declarations:

interface DataInterface extends SerializedByVerbs {}

class StringData implements DataInterface
{
    use NormalizeToPropertiesAndClassName;

    public string $value;
}

class NumberData implements DataInterface
{
    use NormalizeToPropertiesAndClassName;

    public int $value;
}

This change is non-breaking.

If you prefer a different approach to implement the behaviour, please let me know.

@gehrisandro
Copy link
Author

Hi @inxilpro @DanielCoulbourne

Any chance to have a look on this PR? It is only a small change to the SelfSerializingNormalizer which allows deserializing properties with union or interface types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant