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] Add options to JsonDecode and JsonEncode to wrap/unwrap json data#28887
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
Add options to JsonDecode and JsonEncode to wrap/unwrap json dataAdd options to JsonDecode and JsonEncode to wrap/unwrap json dataAdd options to JsonDecode and JsonEncode to wrap/unwrap json dataAdd options to JsonDecode and JsonEncode to wrap/unwrap json dataAdd options to JsonDecode and JsonEncode to wrap/unwrap json data
ogizanagi 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.
Thanks@nonanerz for suggesting. I'm not sure this is a feature we want in core, but let's see what others think.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
mcfedr commentedOct 17, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I like this idea, its a common JSON API patternt to have the top level object nested, and you have to create lots of extra model classes to handle this. E.g. some api gives {user: {name: fred, id: 1}} - at the moment to use the serializer with this I have to create a class that I dont really need: class UserResponse {functionsetUser(User$u) {...}} With this it can be avoided and become |
…n_decoder# Conflicts:#src/Symfony/Component/Serializer/Encoder/JsonDecode.php#src/Symfony/Component/Serializer/Encoder/JsonEncode.php
ogizanagi commentedNov 14, 2018
Wild thoughts: do we need this as |
fabpot commentedFeb 21, 2019
What's the status of this PR? |
…n_decoder# Conflicts:#src/Symfony/Component/Serializer/Encoder/JsonDecode.php#src/Symfony/Component/Serializer/Encoder/JsonEncode.php#src/Symfony/Component/Serializer/Tests/Encoder/JsonDecodeTest.php#src/Symfony/Component/Serializer/Tests/Encoder/JsonEncodeTest.php
fabpot commentedMar 31, 2019
This PR should be rebased as it contains a merge commit that will forbid it to be merged? |
fabpot commentedApr 6, 2019
closing in favor of#30894 |
This PR was merged into the 5.1-dev branch.Discussion----------[Serializer] UnwrappingDenormalizer| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | n/a| License | MIT| Doc PR | n/aUnwrappingDenormalizer, registered with very high priority. Unwrapping the data if UNWRAP_PATH is provided.Very often some APIs give nested responses in which we need only the child object. With UnwrappingDenormalizer we can get the needed object without creating unnecessary Model class that we don't really need.Regarding to#28887 and#30894Usage:`$serialiser->deserialize('{"baz": {"foo": "bar", "inner": {"title": "value", "numbers": [5,3]}}}', Object::class, ['UnwrappingDenormalizer::UNWRAP_PATH' => '[baz][inner]'])`Commits-------00d103d UnwrappingDenormalizer
This PR was merged into the 5.1-dev branch.Discussion----------[Serializer] UnwrappingDenormalizer| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | n/a| License | MIT| Doc PR | n/aUnwrappingDenormalizer, registered with very high priority. Unwrapping the data if UNWRAP_PATH is provided.Very often some APIs give nested responses in which we need only the child object. With UnwrappingDenormalizer we can get the needed object without creating unnecessary Model class that we don't really need.Regarding tosymfony/symfony#28887 andsymfony/symfony#30894Usage:`$serialiser->deserialize('{"baz": {"foo": "bar", "inner": {"title": "value", "numbers": [5,3]}}}', Object::class, ['UnwrappingDenormalizer::UNWRAP_PATH' => '[baz][inner]'])`Commits-------00d103d5f7 UnwrappingDenormalizer
This PR was merged into the 5.1-dev branch.Discussion----------[Serializer] UnwrappingDenormalizer| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | n/a| License | MIT| Doc PR | n/aUnwrappingDenormalizer, registered with very high priority. Unwrapping the data if UNWRAP_PATH is provided.Very often some APIs give nested responses in which we need only the child object. With UnwrappingDenormalizer we can get the needed object without creating unnecessary Model class that we don't really need.Regarding tosymfony/symfony#28887 andsymfony/symfony#30894Usage:`$serialiser->deserialize('{"baz": {"foo": "bar", "inner": {"title": "value", "numbers": [5,3]}}}', Object::class, ['UnwrappingDenormalizer::UNWRAP_PATH' => '[baz][inner]'])`Commits-------00d103d5f7 UnwrappingDenormalizer
Add options to JsonDecode and JsonEncode to wrap/unwrap json data
Add options to JsonDecode and JsonEncode to wrap/unwrap json data.
So you can use:
$serialiser->deserialize("{object: {value: 1, other: 2}}", Object::class, ['json_root_key' => 'object'])