Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Serializer] Fixed framework.serializer.default_context is not working for JsonEncoder#45554
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
dunglas left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Ad this is a new feature, this should target the 5.c branch. Also, maybe should we allow providing different contexts for encoding and decoding.
| protected$decodingImpl; | ||
| publicfunction__construct(JsonEncode$encodingImpl =null,JsonDecode$decodingImpl =null) | ||
| publicfunction__construct(array$defaultContext = [],JsonEncode$encodingImpl =null,JsonDecode$decodingImpl =null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This is a BC break, could you move this parameter at the end of the list please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I understand, but I'm not sure how to set differentdefaultContext for encoding and decoding, becauseJsonEncode andJsonDecode are not passed intoJsonEncoder as a service, and other places are the samedefaultContext set inframework.serializer.default_context, LikeXmlEncoder orDateTimeNormalizer.
also I have tried providing thedefaultContext parameter at the end, but this raises an error inDefinitionErrorExceptionPass:
Invalid constructor argument 3 for service "serializer.encoder.json": argument 1 must be defined before. Check your service definition.Do you have any idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Actually, the proper solution is maybe to register them as services indeed!
fabpot commentedJul 21, 2022
@siganushka Are you still interested in moving this PR forward? |
nicolas-grekas commentedSep 28, 2022
Thank you@siganushka. |
Uh oh!
There was an error while loading.Please reload this page.
Fixed
framework.serializer.default_contextis not working forJsonEncoderlike
XmlEncoderorDateTimeNormalizer, thearray $defaultContextargument bindings fromSerializerPass, but not working forJsonEncoder, I addedarray $defaultContextargument and passed toJsonEncodeandJsonDecode.https://github.com/symfony/serializer/blob/5.4/DependencyInjection/SerializerPass.php#L69-L75