Skip to content

Commit 9e2d4f6

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: Rename context flag Update components/serializer.rst Update components/serializer.rst Update components/serializer.rst Update components/serializer.rst Fix broken code example Add feature description
2 parents a40b44a + 218ba02 commit 9e2d4f6

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

components/serializer.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,33 @@ to ``true``::
12531253
$result = $normalizer->normalize($dummy, 'json', [AbstractObjectNormalizer::SKIP_NULL_VALUES => true]);
12541254
// ['bar' => 'notNull']
12551255

1256+
Require all Properties
1257+
----------------------
1258+
1259+
By default, the Serializer will add ``null`` to nullable properties when the parameters for those are not provided.
1260+
You can change this behavior by setting the ``AbstractNormalizer::REQUIRE_ALL_PROPERTIES`` context option
1261+
to ``true``::
1262+
1263+
class Dummy
1264+
{
1265+
public function __construct(
1266+
public string $foo,
1267+
public ?string $bar,
1268+
) {
1269+
}
1270+
}
1271+
1272+
$data = ['foo' => 'notNull'];
1273+
1274+
$normalizer = new ObjectNormalizer();
1275+
$result = $normalizer->denormalize($data, Dummy::class, 'json', [AbstractNormalizer::REQUIRE_ALL_PROPERTIES => true]);
1276+
// throws Symfony\Component\Serializer\Exception\MissingConstructorArgumentException
1277+
1278+
.. versionadded:: 6.3
1279+
1280+
The ``AbstractNormalizer::PREVENT_NULLABLE_FALLBACK`` context option
1281+
was introduced in Symfony 6.3.
1282+
12561283
Skipping Uninitialized Properties
12571284
---------------------------------
12581285

0 commit comments

Comments
 (0)