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);
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 strategytoPayload
is getting serialized, but when unserializingfromPayload
is never called.For instance:
Expected output:
Actual output: