Skip to content

Outermost class never uses a default caster #73

@axlon

Description

@axlon

What's wrong

When hydrating a payload back to an object, the hydrator never checks if a default caster exists for the outer most object. Typically this isn't a problem, because most of the time the class you are hydrating consists of properties that the mapper can hydrate (either through casters or just by using reflection). However this also means that you can't use a caster to call another caster (by calling $hydrator->hydrateObject(Some::Class, $somePayload)).

My use case

My current use case for calling one caster from another is that I'm trying to support array shapes, this involves providing an attribute for each key in the array that needs to be cast to a type (e.g. #[CastArrayItem('foo', Foo::class)]), as well as using this package's #[SerializeArrayItems]. For the most part this works fine, but I'm currently unable to hydrate any values that require a caster.

PS. Am happy to attempt a PR if you feel this is the right direction

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