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

Allow returning null from NormalizerInterface::normalize #34340

Merged
merged 1 commit into from Nov 13, 2019

Conversation

teohhanhui
Copy link
Contributor

Q A
Branch? 3.4
Bug fix? yes?
New feature? no
Deprecations? no
Tickets N/A
License MIT
Doc PR N/A

Looking at the code, it seems that a normalizer might be called with a null value for $data, and thus it's only sensible that it be allowed to return null too:

// If a normalizer supports the given data, use it
if ($normalizer = $this->getNormalizer($data, $format, $context)) {
return $normalizer->normalize($data, $format, $context);
}
if (null === $data || is_scalar($data)) {
return $data;
}

Updating the phpdoc to match.

fabpot pushed a commit that referenced this pull request Nov 13, 2019
… (teohhanhui)

This PR was merged into the 3.4 branch.

Discussion
----------

Allow returning null from NormalizerInterface::normalize

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes?
| New feature?  | no
| Deprecations? | no
| Tickets       | N/A
| License       | MIT
| Doc PR        | N/A

Looking at the code, it seems that a normalizer might be called with a `null` value for `$data`, and thus it's only sensible that it be allowed to return `null` too:

https://github.com/symfony/symfony/blob/7064ff35f2539e2c915257a50eb37839b485dbeb/src/Symfony/Component/Serializer/Serializer.php#L141-L148

Updating the phpdoc to match.

Commits
-------

1c8edc5 Allow returning null from NormalizerInterface::normalize
@fabpot fabpot merged commit 1c8edc5 into symfony:3.4 Nov 13, 2019
@nicolas-grekas
Copy link
Member

Thank you @teohhanhui

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.

None yet

4 participants