IBX-6640: Fixed infinite loop when Normalizer returns an object #75
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
v4.5
When trying to fix an incorrect REST response shape, I have found out that the solution expected cannot work, because it relies on object being returned from Normalizer.
The incorrect response is (note the "data" property):
While the expected output would be:
To fix this,
Ibexa\Rest\Output\Generator\Json\FieldTypeHashGenerator::generateObjectValue()
cannot callIbexa\Rest\Output\Generator\Json\FieldTypeHashGenerator::generateValue()
, because this results in an infinite loop.When looking at
Ibexa\Rest\Output\Generator\Json\FieldTypeHashGenerator::generateValue()
you can notice that it works on 4 data types:null
scalar
array
object
null
andscalar
work properly, and loop is broken immediately, so we can skip the additional call.object
in current shape becomes an infinite loop. Those two methods keep calling each other.array
has the only special effect among all 4, where it performs a few list related tasks.See
https://github.com/symfony/symfony/blob/0659364bbc51920ab6475186e40d1bf06a637047/src/Symfony/Component/Serializer/Serializer.php#L166-L173
and
https://github.com/symfony/symfony/blob/0659364bbc51920ab6475186e40d1bf06a637047/src/Symfony/Component/Serializer/Serializer.php#L51-L55
for explanation why objects sometimes are needed after normalization.
TODO:
$ composer fix-cs
).