Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.3k
[Serializer] SerializedPath documentation#17396
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
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
81 changes: 81 additions & 0 deletionsserializer.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -368,6 +368,87 @@ stored in one of the following locations: | ||
| .. _serializer-enabling-metadata-cache: | ||
| Using nested attributes | ||
| ----------------------- | ||
| To map nested properties, a ``SerializedPath`` can be defined with annotations, | ||
boenner marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| attributes and YAML or XML configurations: | ||
| .. configuration-block:: | ||
| .. code-block:: php-annotations | ||
| namespace App\Model; | ||
| use Symfony\Component\Serializer\Annotation\SerializedPath; | ||
| class Person | ||
| { | ||
| /** | ||
| * @SerializedPath("[profile][information][birthday]") | ||
| */ | ||
| private string $birthday; | ||
| // ... | ||
| } | ||
| .. code-block:: php-attributes | ||
| namespace App\Model; | ||
| use Symfony\Component\Serializer\Annotation\SerializedPath; | ||
| class Person | ||
| { | ||
| #[SerializedPath('[profile][information][birthday]')] | ||
| private string $birthday; | ||
| // ... | ||
| } | ||
| .. code-block:: yaml | ||
| App\Model\Person: | ||
| attributes: | ||
| dob: | ||
| serialized_path: '[profile][information][birthday]' | ||
| .. code-block:: xml | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <serializer xmlns="http://symfony.com/schema/dic/serializer-mapping" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://symfony.com/schema/dic/serializer-mapping | ||
| https://symfony.com/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd" | ||
| > | ||
| <class name="App\Model\Person"> | ||
| <attribute name="dob" serialized-path="[profile][information][birthday]"/> | ||
| </class> | ||
| </serializer> | ||
| .. versionadded:: 6.2 | ||
| The option to configure a ``SerializedPath`` was introduced in Symfony 6.2. | ||
| Using the configuration from above, denormalizing with a metadata-aware | ||
| normalizer will write the ``birthday`` field from ``$data`` onto the ``Person`` | ||
| object:: | ||
| $data = [ | ||
| 'profile' => [ | ||
| 'information' => [ | ||
| 'birthday' => '01-01-1970', | ||
| ], | ||
| ], | ||
| ]; | ||
| $person = $normalizer->denormalize($data, Person::class, 'any'); | ||
| $person->getBirthday(); // 01-01-1970 | ||
| When using annotations or attributes, the ``SerializedPath`` can either | ||
| be set on the property or the associated getter. The ``SerializedPath`` | ||
| cannot be used in combination with a ``SerializedName`` for the same propety. | ||
| The given path must be a string that can be parsed as a ``PropertyPath``. | ||
| Configuring the Metadata Cache | ||
| ------------------------------ | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.