@@ -1193,6 +1193,41 @@ to ``true``::
1193
1193
$result = $normalizer->normalize($dummy, 'json', [AbstractObjectNormalizer::SKIP_NULL_VALUES => true]);
1194
1194
// ['bar' => 'notNull']
1195
1195
1196
+ Skipping Uninitialized Properties
1197
+ ---------------------------------
1198
+
1199
+ In PHP, typed properties have an ``uninitialized `` state which is different
1200
+ from the default ``null `` of untyped properties. When you try to access a typed
1201
+ property before giving it an explicit value, you get an error.
1202
+
1203
+ To avoid the Serializer throwing an error when serializing or normalizing an
1204
+ object with uninitialized properties, by default the object normalizer catches
1205
+ these errors and ignores such properties.
1206
+
1207
+ You can disable this behavior by setting the ``AbstractObjectNormalizer::SKIP_UNINITIALIZED_VALUES ``
1208
+ context option to ``false ``::
1209
+
1210
+ class Dummy {
1211
+ public string $foo = 'initialized';
1212
+ public string $bar; // uninitialized
1213
+ }
1214
+
1215
+ $normalizer = new ObjectNormalizer();
1216
+ $result = $normalizer->normalize(new Dummy(), 'json', [AbstractObjectNormalizer::SKIP_UNINITIALIZED_VALUES => false]);
1217
+ // throws Symfony\Component\PropertyAccess\Exception\UninitializedPropertyException as normalizer cannot read uninitialized properties
1218
+
1219
+ .. note ::
1220
+
1221
+ Calling ``PropertyNormalizer::normalize `` or ``GetSetMethodNormalizer::normalize ``
1222
+ with ``AbstractObjectNormalizer::SKIP_UNINITIALIZED_VALUES `` context option set
1223
+ to ``false `` will throw an ``\Error `` instance if the given object has uninitialized
1224
+ properties as the normalizer cannot read them (directly or via getter/isser methods).
1225
+
1226
+ .. versionadded :: 5.4
1227
+
1228
+ The ``AbstractObjectNormalizer::SKIP_UNINITIALIZED_VALUES `` constant was
1229
+ introduced in Symfony 5.4.
1230
+
1196
1231
.. _component-serializer-handling-circular-references :
1197
1232
1198
1233
Collecting Type Errors While Denormalizing
0 commit comments