Skip to content

[Serializer] Allow to provide (de)normalization context in mapping #14988

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
fabpot opened this issue Feb 16, 2021 · 8 comments
Closed

[Serializer] Allow to provide (de)normalization context in mapping #14988

fabpot opened this issue Feb 16, 2021 · 8 comments
Labels
hasPR A Pull Request has already been submitted for this issue. Keep open Serializer
Milestone

Comments

@fabpot
Copy link
Member

fabpot commented Feb 16, 2021

Q A
Feature PR symfony/symfony#39399
PR author(s) @ogizanagi
Merged in 5.3-dev
@xabbuh xabbuh added this to the 5.3 milestone Feb 17, 2021
@carsonbot
Copy link
Collaborator

Thank you for this issue.
There has not been a lot of activity here for a while. Has this been resolved?

@ogizanagi
Copy link
Contributor

Not yet. Let me add a section in https://symfony.com/doc/current/components/serializer.html in the upcoming days!

@alexander-schranz
Copy link
Contributor

alexander-schranz commented Mar 1, 2022

I'm currently searching for docs about the context attribute. To validate if it maybe can fix my problem I have a subentity and currently it is serialized this way:

{
   "id": 1,
   "subEntity": {
       "firstName": "Test",
       "lastName": "Test"
   }
}

instead I want to have it this way:

{
   "id": 1,
   "firstName": "Test",
   "lastName": "Test"
}

In the JMS Serializer this is done via @Inline attribute. So I'm searching for something similar in the symfony serializer as we want to replace jms with symfony here.

@ogizanagi is that something which is possible via the context attribute?

@ogizanagi
Copy link
Contributor

is that something which is possible via the context attribute?

Not yet since the ObjectNormalizer does not support such a feature yet.
But it'll probably help, since it'll allow to declare locally a context on the attribute of the root entity, to inline the subentity attributes if such a feature was introduced in the ObjectNormalizer.

@alexander-schranz
Copy link
Contributor

@ogizanagi Thx for your response. Atleast I know that I did not miss something. Still like the #[Context] feature as I use it to have for a subentity another serialization group then for the parent entity. Nice work 👍

@wouterj
Copy link
Member

wouterj commented Sep 20, 2022

Friendly ping @ogizanagi. Is there anything I can help you with to document this cool new attribute?

@ogizanagi
Copy link
Contributor

Sorry, I didn't take the time yet to document this.
Feel free to do so, otherwise I'll try to keep it in mind whenever I have some time. 🙂

@ogizanagi
Copy link
Contributor

Finally took the time to document this 😅 See #17345

@xabbuh xabbuh added the hasPR A Pull Request has already been submitted for this issue. label Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hasPR A Pull Request has already been submitted for this issue. Keep open Serializer
Projects
None yet
Development

No branches or pull requests

6 participants