symfony-docs
symfony-docs copied to clipboard
[Serializer] Allow to provide (de)normalization context in mapping
Q | A |
---|---|
Feature PR | symfony/symfony#39399 |
PR author(s) | @ogizanagi |
Merged in | 5.3-dev |
Thank you for this issue. There has not been a lot of activity here for a while. Has this been resolved?
Not yet. Let me add a section in https://symfony.com/doc/current/components/serializer.html in the upcoming days!
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?
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.
@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 👍
Friendly ping @ogizanagi. Is there anything I can help you with to document this cool new attribute?
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. 🙂
Finally took the time to document this 😅 See https://github.com/symfony/symfony-docs/pull/17345