fallback to array casting for internal objects
This commit is contained in:
parent
f08978c567
commit
102f16cb9e
2 changed files with 16 additions and 2 deletions
|
@ -41,6 +41,16 @@ class EntityStrategy implements DeserializeStrategyInterface
|
|||
$reflection = new \ReflectionClass($type);
|
||||
$instance = new $type();
|
||||
|
||||
if (!$reflection->isUserDefined()) {
|
||||
if (is_iterable($value)) {
|
||||
foreach ($value as $field => $content) {
|
||||
$instance->$field = $content;
|
||||
}
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
foreach ($reflection->getProperties() as $property) {
|
||||
static::deserializeProperty($instance, $property, $value);
|
||||
}
|
||||
|
|
|
@ -36,9 +36,13 @@ class EntityStrategy implements SerializeStrategyInterface
|
|||
public function serialize($value)
|
||||
{
|
||||
$result = [];
|
||||
$ref = new \ReflectionClass(get_class($value));
|
||||
$reflection = new \ReflectionClass(get_class($value));
|
||||
|
||||
foreach ($ref->getProperties() as $property) {
|
||||
if (!$reflection->isUserDefined()) {
|
||||
return (array) $value;
|
||||
}
|
||||
|
||||
foreach ($reflection->getProperties() as $property) {
|
||||
static::serializeProperty($value, $property, $result);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue