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