Closed
Description
Description
Originally described in #38993 (comment), I'd suggest adding a new @Serializer\Context
annotation/php attribute/xml and yaml mapping config.
It could accept a normalizationContext
, denormalizationContext
or both context
at once (default option), and perhaps a traverse
option to forward the context on deeper nodes if any (when applied on class/object properties).
Example
class Foo
{
/**
* @var \DateTime
*
* @Serializer\Context({
* DateTimeNormalizer::FORMAT_KEY = 'Y-m-d',
* })
*/
public $date;
}
This specifically changes the format used to (de)normalize the Foo::$date
property while keeping the default context (or the one provided in the (de)serialize
call) everywhere else.
Any normalizer with specific context options would benefit from it, as it'll allow to configure anything on a per-case basis.