Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Serializer] Mention adder method to deserialize an array of objects #17956

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

Conversation

alexandre-daubois
Copy link
Member

After spending a whole day with a colleague to try to deserialize/denormalize an array of objects a few weeks ago without succeeding, I thought that I might share this "adder method" tip to everyone now that I finally found the solution... 😅

@@ -1751,6 +1751,61 @@ will be thrown. The type enforcement of the properties can be disabled by settin
the serializer context option ``ObjectNormalizer::DISABLE_TYPE_ENFORCEMENT``
to ``true``.

It is also possible to denormalize an array of object. To do so, ensure
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
It is also possible to denormalize an array of object. To do so, ensure
It is also possible to denormalize an array of objects. To do so, ensure

?

@@ -1751,6 +1751,61 @@ will be thrown. The type enforcement of the properties can be disabled by settin
the serializer context option ``ObjectNormalizer::DISABLE_TYPE_ENFORCEMENT``
to ``true``.

It is also possible to denormalize an array of object. To do so, ensure
the owner object contains a adder method, so the Serializer is able to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
the owner object contains a adder method, so the Serializer is able to
the owner object contains an adder method, so the Serializer is able to

@@ -1751,6 +1751,61 @@ will be thrown. The type enforcement of the properties can be disabled by settin
the serializer context option ``ObjectNormalizer::DISABLE_TYPE_ENFORCEMENT``
to ``true``.

It is also possible to denormalize an array of object. To do so, ensure
the owner object contains a adder method, so the Serializer is able to
guess the type of object to denormalize in your collection. Let's
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
guess the type of object to denormalize in your collection. Let's
guess the type of the object to denormalize in your collection. Let's

It is also possible to denormalize an array of object. To do so, ensure
the owner object contains a adder method, so the Serializer is able to
guess the type of object to denormalize in your collection. Let's
rename ``$inner`` to ``$inners`` and create a adder method::
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rename ``$inner`` to ``$inners`` and create a adder method::
rename ``$inner`` to ``$inners`` and create an adder method::

}

// This is the key method that will allow the Serializer
// to know the type of object of your collection
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// to know the type of object of your collection
// to know the type of the object of your collection

@wouterj
Copy link
Member

wouterj commented Feb 23, 2023

As indicated in #17814, this article is going to be removed. Let's not add more text to it

@alexandre-daubois
Copy link
Member Author

Oh yes sorry, I forgot about it. You're right. I think it worth mention it, feel free to take this PR's content if needed 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants