Description
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
-
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 -
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. (?)
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