-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Serializer] Normalizers can serialize collections and scalars #13500
Conversation
Would you be able to cover this with tests? |
@jakzal tests added. |
5a39d19
to
9bbe56f
Compare
$class = get_class($data); | ||
if (isset($this->normalizerCache[$class][$format])) { | ||
return $this->normalizerCache[$class][$format]; | ||
if ($isObject = is_object($data)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you can pass something else than an object to this method, you need to update the phpdoc
For Traversable objects, it is already possible to customize it |
9bbe56f
to
2381c7d
Compare
@stof right. Fixed the PR description and the PHPDoc. |
The Travis failure seems unrelated with this PR. |
Thank you @dunglas. |
… scalars (dunglas) This PR was squashed before being merged into the 2.7 branch (closes #13500). Discussion ---------- [Serializer] Normalizers can serialize collections and scalars | Q | A | ------------- | --- | Bug fix? | yes | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT | Doc PR | n/a Currently, the logic for serializing `array` and scalars is hardcoded in the serializer. This is not possible to have a custom serializer normalizing collections. This a big limitation, for instance it's not possible to create an normalizer creating [Hydra collections](http://www.hydra-cg.com/spec/latest/core/#h-collections) for a PHP array. This PR fix that. Commits ------- 1cf8eb2 [Serializer] Normalizers can serialize collections and scalars
…dunglas) This PR was merged into the 2.7 branch. Discussion ---------- [Serializer] Ignore \Traversable in default normalizers. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #14495 | License | MIT | Doc PR | n/a Before the merge of #13500, default normalizers where never called for `\Traversable` objects. This PR restore the previous behavior in a cleaner way. This is also convenient when dealing with Doctrine's ArrayCollection and serialization groups (see #14495). ping @symfony/deciders Commits ------- c9bff46 [Serializer] Ignore \Traversable in default normalizers. Close #14495.
Currently, the logic for serializing
array
and scalars is hardcoded in the serializer. This is not possible to have a custom serializer normalizing collections. This a big limitation, for instance it's not possible to create an normalizer creating Hydra collections for a PHP array.This PR fix that.