Skip to content

Commit

Permalink
Fix castable value object not serialized correctly (#39020)
Browse files Browse the repository at this point in the history
  • Loading branch information
kminek authored Sep 28, 2021
1 parent 35f28c7 commit 95c8607
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ protected function isClassDeviable($key)
protected function isClassSerializable($key)
{
return $this->isClassCastable($key) &&
method_exists($this->parseCasterClass($this->getCasts()[$key]), 'serialize');
method_exists($this->resolveCasterClass($key), 'serialize');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ public function testWithCastableInterface()
]);

$this->assertInstanceOf(ValueObject::class, $model->value_object_with_caster);
$this->assertSame(serialize(new ValueObject('hello')), $model->toArray()['value_object_with_caster']);

$model->setRawAttributes([
'value_object_caster_with_argument' => null,
Expand Down Expand Up @@ -418,7 +419,7 @@ public function __construct(string $name)

public static function castUsing(array $arguments)
{
return new class(...$arguments) implements CastsAttributes
return new class(...$arguments) implements CastsAttributes, SerializesCastableAttributes
{
private $argument;

Expand All @@ -440,6 +441,11 @@ public function set($model, $key, $value, $attributes)
{
return serialize($value);
}

public function serialize($model, $key, $value, $attributes)
{
return serialize($value);
}
};
}
}
Expand Down

0 comments on commit 95c8607

Please sign in to comment.