-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer > JSON Encoding] Allow configuring default options #47183
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
Comments
The serializer should allow you to set the context for the JSON Encoder via the Conext Builder. Which should also means its customizable via the See for details: #47012 |
We should also set |
Indeed - there's certainly a little work to be done around the serializer for 6.2. Unfortunately, I don't have the bandwidth to take a look at any of it :-(. |
@nicolas-grekas i created the PR to set JSON_PRESERVE_ZERO_FRACTION by default. if #47012 is correct that it should be possible to configure the default context in that way, then this issue is actually a documentation request because it would already be possible to do what i wanted. https://symfony.com/doc/current/reference/configuration/framework.html#serializer does not mention the default_context option of the serializer configuration. |
For the JSON Encoder/Decoder, the context from the configuration is not used, as described in #47012 (comment) |
Is is mentioned here, however: https://symfony.com/doc/current/serializer.html#serializer-context |
…ault (dbu) This PR was merged into the 6.2 branch. Discussion ---------- [Serializer] enable JSON_PRESERVE_ZERO_FRACTION by default this makes json output float values that happen to be full numbers with a `.0`, so `4.0` or `0.0` instead of `4` resp `0`. that in turn helps when consuming the json in a type-safe language. | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | As discussed in #47183 | License | MIT | Doc PR | - In #47183, @nicolas-grekas said that we should enable the preserve zero fraction flag by default in the serializer. I am a bit unsure if we should consider this a BC break, as it does change the output of JSON data. Should it be considered a bugfix against 6.1, a feature against 6.2 or a BC break that has to wait until 7.0? Commits ------- 9480e2b enable JSON_PRESERVE_ZERO_FRACTION by default
the functionality to set configuration in the context has been implemented in #45554 i am adding documentation in symfony/symfony-docs#17305 |
This PR was merged into the 5.4 branch. Discussion ---------- document serializer default_context fix symfony/symfony#47183 add missing documentation for this serializer configuration option Commits ------- 664bc4b document serializer default_context
Description
I need to configure json encoding options (in my case JSON_PRESERVE_ZERO_FRACTION). but the configuration for the
serializer
section does not allow to set options.It would be nice to allow to configure options for the encoder and decoder in the configuration.
Example
it would be nice if i could do something like this:
my workaround is this compiler pass:
The text was updated successfully, but these errors were encountered: