Skip to content

Commit 034f0f6

Browse files
committed
[Serializer] Documenting the new SKIP_UNINITIALIZED_VALUES option
1 parent 90cb996 commit 034f0f6

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

components/serializer.rst

+21
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,27 @@ to ``true``::
11741174
$result = $normalizer->normalize($dummy, 'json', [AbstractObjectNormalizer::SKIP_NULL_VALUES => true]);
11751175
// ['bar' => 'notNull']
11761176

1177+
Skipping uninitialized properties
1178+
---------------------------------
1179+
1180+
PHP 7.4 introduced typed properties, which have a new state - ``uninitialized``.
1181+
This is different from the default ``null`` of untyped properties.
1182+
When you try to access it before giving it an explicit value - you get an error.
1183+
1184+
To avoid serializer throwing an error when serializing or normalizing an object with
1185+
uninitialized properties - then you can set ``AbstractObjectNormalizer::SKIP_UNINITIALIZED_VALUES`` to ``true``.
1186+
1187+
.. note::
1188+
1189+
Error is thrown only if you inject a ``ClassMetadataFactory`` into the normalizer.
1190+
Otherwise the properties are checked with reflection and uninitialized ones are skipped.
1191+
This option is useful when, for example, you want to serialize subset of properties by serialization groups,
1192+
which requires the ``ClassMetadataFactory``
1193+
1194+
.. versionadded:: 5.4
1195+
1196+
The ``AbstractObjectNormalizer::SKIP_UNINITIALIZED_VALUES`` constant was introduced in Symfony 5.4.
1197+
11771198
.. _component-serializer-handling-circular-references:
11781199

11791200
Handling Circular References

0 commit comments

Comments
 (0)