Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Serializer > Context (annotation) > Callbacks] Callbacks defined in the attribute Context annotation are ignored #43563

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

Closed
yyaremenko opened this issue Oct 18, 2021 · 1 comment

Comments

@yyaremenko
Copy link

Symfony version(s) affected: 5.3

Description
According to this post, the Context annotation allows to add context per attribute.

If you look closely into the code though, you'll discover that

  1. Upon normalization, the callbacks are only retrieved from the context passed explicitly to normalize() method:
    https://github.com/symfony/serializer/blob/5d7f068253ac3e7c62964ebdda491b06d401059a/Normalizer/AbstractObjectNormalizer.php#L187

  2. Upon denormalization, either callbacks passed explicitly to denormalize() or passed as annotation, e.g.

/**
 * @Context({
 *     "denormalizationContext": { "callbacks": { "someValue": "doSomeStuffOnDenormalization" } }
 * })
 */
private int $someValue;

are completely ignored. (?)

https://github.com/symfony/serializer/blob/5d7f068253ac3e7c62964ebdda491b06d401059a/Normalizer/AbstractObjectNormalizer.php#L401

How to reproduce
Add Context annotation to an attribute, with callbacks for normalization / denormalization and see if they are actually called.

Possible Solution
Add the missing functionality

@benjaminmal
Copy link

Any news on this issue? 😀

nicolas-grekas added a commit that referenced this issue Feb 11, 2022
…jaminmal)

This PR was squashed before being merged into the 4.4 branch.

Discussion
----------

[Serializer] Fix ignored callbacks in denormalization

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #43563-2
| License       | MIT
| Doc PR        | -

Stop ignoring callbacks in denormalization. #freeTheCallbacks!!!

Commits
-------

abe18a0 [Serializer] Fix ignored callbacks in denormalization
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants