Skip to content

Commit c0eb95c

Browse files
committed
minor #17979 [Serializer] Add feature description for AbstractNormalizer::REQUIRE_ALL_PROPERTIES context option (Christian Kolb, christian-kolb)
This PR was merged into the 6.3 branch. Discussion ---------- [Serializer] Add feature description for `AbstractNormalizer::REQUIRE_ALL_PROPERTIES` context option This PR adds the feature description for the new context flag for the Serializer component introduced here: symfony/symfony#49553 Commits ------- 71a4ef4 Rename context flag ea5c341 Update components/serializer.rst 3b24418 Update components/serializer.rst e1f5d7c Update components/serializer.rst b665eeb Update components/serializer.rst 0b49d9b Fix broken code example 1b0e274 Add feature description
2 parents 9a5fd75 + 71a4ef4 commit c0eb95c

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
@@ -1255,6 +1255,33 @@ to ``true``::
12551255
$result = $normalizer->normalize($dummy, 'json', [AbstractObjectNormalizer::SKIP_NULL_VALUES => true]);
12561256
// ['bar' => 'notNull']
12571257

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

0 commit comments

Comments
 (0)