mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 06:15:19 +08:00
Fix #16334: Serializer support \JsonSerializable
This commit is contained in:
@ -137,7 +137,7 @@ class Serializer extends Component
|
||||
* Serializes the given data into a format that can be easily turned into other formats.
|
||||
* This method mainly converts the objects of recognized types into array representation.
|
||||
* It will not do conversion for unknown object types or non-object data.
|
||||
* The default implementation will handle [[Model]] and [[DataProviderInterface]].
|
||||
* The default implementation will handle [[Model]], [[DataProviderInterface]] and [\JsonSerializable](https://www.php.net/manual/ru/class.jsonserializable.php).
|
||||
* You may override this method to support more object types.
|
||||
* @param mixed $data the data to be serialized.
|
||||
* @return mixed the converted data.
|
||||
@ -146,6 +146,8 @@ class Serializer extends Component
|
||||
{
|
||||
if ($data instanceof Model && $data->hasErrors()) {
|
||||
return $this->serializeModelErrors($data);
|
||||
} elseif ($data instanceof \JsonSerializable) {
|
||||
return $data->jsonSerialize();
|
||||
} elseif ($data instanceof Arrayable) {
|
||||
return $this->serializeModel($data);
|
||||
} elseif ($data instanceof DataProviderInterface) {
|
||||
|
Reference in New Issue
Block a user