Repository navigation
Conversation
TamasSzigeti
left a comment
There was a problem hiding this comment.
My test still fails at denormalization
Symfony\Component\Serializer\Exception\NotNormalizableValueException: Data expected to be "ArrayObject[]", "ArrayObject" given.
…
/app/vendor/dunglas/doctrine-json-odm/src/SerializerTrait.php:91
dunglas
left a comment
There was a problem hiding this comment.
Thanks for the fix. One concern: `$normalizedData[self::KEY_TYPE] = $typeName` moves `#type` from the first to the last key of every stored document. This changes the output for `json` columns (which preserve key order) and no longer matches the README examples.
Casting keeps the current shape and fixes the `ArrayObject` case, since the result always contains `#type` and is never empty:
```php
$valueData = is_scalar($normalizedData) ? [self::KEY_SCALAR => $normalizedData] : (array) $normalizedData;
```
I checked that `testEmptyArrayAsArrayObject` passes with this change. `testArrayObjectNormalization` would need to assert the `#type` key instead of the `ArrayObject` instance.
Minor: in `denormalize()`, `unset($data[self::KEY_TYPE])` mutates the caller's `ArrayObject`. Either drop the `ArrayObject` handling there (`json_decode` always returns arrays) or convert it first with `getArrayCopy()`.
Fixes #149
These changes add support for
ArrayObjectas a result of object normalization and cover issue #149 with test.