Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Serializer] Add a way to provide a context in mapping #39039

Copy link
Copy link
Closed
@ogizanagi

Description

@ogizanagi
Issue body actions

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.