Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

dunglas
Copy link
Member

@dunglas dunglas commented Jan 23, 2015

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 for a PHP array.

This PR fix that.

@jakzal
Copy link
Contributor

jakzal commented Jan 23, 2015

Would you be able to cover this with tests?

dunglas added a commit to dunglas/symfony that referenced this pull request Jan 23, 2015
@dunglas
Copy link
Member Author

dunglas commented Jan 23, 2015

@jakzal tests added.

dunglas added a commit to dunglas/symfony that referenced this pull request Jan 23, 2015
$class = get_class($data);
if (isset($this->normalizerCache[$class][$format])) {
return $this->normalizerCache[$class][$format];
if ($isObject = is_object($data)) {
Copy link
Member

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

@stof
Copy link
Member

stof commented Jan 26, 2015

For Traversable objects, it is already possible to customize it

@dunglas
Copy link
Member Author

dunglas commented Jan 26, 2015

@stof right. Fixed the PR description and the PHPDoc.

@dunglas
Copy link
Member Author

dunglas commented Feb 2, 2015

The Travis failure seems unrelated with this PR.

@fabpot
Copy link
Member

fabpot commented Feb 11, 2015

Thank you @dunglas.

@fabpot fabpot closed this Feb 11, 2015
fabpot added a commit that referenced this pull request Feb 11, 2015
… 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
fabpot added a commit that referenced this pull request May 5, 2015
…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.
@dunglas dunglas deleted the normalize_collection branch December 5, 2015 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants