@@ -1231,6 +1231,36 @@ to ``true``::
1231
1231
$result = $normalizer->normalize($dummy, 'json', [AbstractObjectNormalizer::SKIP_NULL_VALUES => true]);
1232
1232
// ['bar' => 'notNull']
1233
1233
1234
+ Skipping Uninitialized Properties
1235
+ ---------------------------------
1236
+
1237
+ In PHP, typed properties have an ``uninitialized `` state which is different
1238
+ from the default ``null `` of untyped properties. When you try to access a typed
1239
+ property before giving it an explicit value, you get an error.
1240
+
1241
+ To avoid the Serializer throwing an error when serializing or normalizing an
1242
+ object with uninitialized properties, by default the object normalizer catches
1243
+ these errors and ignores such properties.
1244
+
1245
+ You can disable this behavior by setting the ``AbstractObjectNormalizer::SKIP_UNINITIALIZED_VALUES ``
1246
+ context option to ``false ``::
1247
+
1248
+ class Dummy {
1249
+ public string $foo = 'initialized';
1250
+ public string $bar; // uninitialized
1251
+ }
1252
+
1253
+ $normalizer = new ObjectNormalizer();
1254
+ $result = $normalizer->normalize(new Dummy(), 'json', [AbstractObjectNormalizer::SKIP_UNINITIALIZED_VALUES => false]);
1255
+ // throws Symfony\Component\PropertyAccess\Exception\UninitializedPropertyException as normalizer cannot read uninitialized properties
1256
+
1257
+ .. note ::
1258
+
1259
+ Calling ``PropertyNormalizer::normalize `` or ``GetSetMethodNormalizer::normalize ``
1260
+ with ``AbstractObjectNormalizer::SKIP_UNINITIALIZED_VALUES `` context option set
1261
+ to ``false `` will throw an ``\Error `` instance if the given object has uninitialized
1262
+ properties as the normalizer cannot read them (directly or via getter/isser methods).
1263
+
1234
1264
.. _component-serializer-handling-circular-references :
1235
1265
1236
1266
Collecting Type Errors While Denormalizing
0 commit comments