Skip to content

PayloadSerializerSupportingObjectMapperAndSerializablePayload does not work recursively #223

Description

@axlon

The PayloadSerializerSupportingObjectMapperAndSerializablePayload only looks at the root type to determine the strategy it should use. Because public methods are serialized by default by the reflection strategy toPayload is getting serialized, but when unserializing fromPayload is never called.

For instance:

class Foo
{
    public function __construct(public Bar $bar) {}
}

class Bar implements SerializablePayload
{
    public function toPayload(): array
    {
        return ['is_bar' => true];
    }

    public static function fromPayload(array $payload): static
    {
        return new static();
    }
}

$strategy = new PayloadSerializerSupportingObjectMapperAndSerializablePayload();
$payload = $strategy->serializePayload(new Foo(new Bar()));
var_dump($payload);

Expected output:

array(1) {
  'bar' =>
  array(1) {
    'is_bar' =>
    bool(true)
  }
}

Actual output:

array(1) {
  'bar' =>
  array(1) {
    'to_payload' =>
    array(1) {
      'is_bar' =>
      bool(true)
    }
  }
}

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