Skip to content

[Serializer] Documenting the new SKIP_UNINITIALIZED_VALUES option #15823

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

Merged
merged 2 commits into from
Oct 26, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[Serializer] Documenting the new SKIP_UNINITIALIZED_VALUES option
  • Loading branch information
vuryss committed Sep 16, 2021
commit 034f0f6a14a854b8df3d1d5ee46e0caa42ef9472
21 changes: 21 additions & 0 deletions components/serializer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,27 @@ to ``true``::
$result = $normalizer->normalize($dummy, 'json', [AbstractObjectNormalizer::SKIP_NULL_VALUES => true]);
// ['bar' => 'notNull']

Skipping uninitialized properties
---------------------------------

PHP 7.4 introduced typed properties, which have a new state - ``uninitialized``.
This is different from the default ``null`` of untyped properties.
When you try to access it before giving it an explicit value - you get an error.

To avoid serializer throwing an error when serializing or normalizing an object with
uninitialized properties - then you can set ``AbstractObjectNormalizer::SKIP_UNINITIALIZED_VALUES`` to ``true``.

.. note::

Error is thrown only if you inject a ``ClassMetadataFactory`` into the normalizer.
Otherwise the properties are checked with reflection and uninitialized ones are skipped.
This option is useful when, for example, you want to serialize subset of properties by serialization groups,
which requires the ``ClassMetadataFactory``

.. versionadded:: 5.4

The ``AbstractObjectNormalizer::SKIP_UNINITIALIZED_VALUES`` constant was introduced in Symfony 5.4.

.. _component-serializer-handling-circular-references:

Handling Circular References
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy