Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc0eb95c

Browse files
committed
minor#17979 [Serializer] Add feature description forAbstractNormalizer::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 optionThis PR adds the feature description for the new context flag for the Serializer component introduced here:symfony/symfony#49553Commits-------71a4ef4 Rename context flagea5c341 Update components/serializer.rst3b24418 Update components/serializer.rste1f5d7c Update components/serializer.rstb665eeb Update components/serializer.rst0b49d9b Fix broken code example1b0e274 Add feature description
2 parents9a5fd75 +71a4ef4 commitc0eb95c

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)

[8]ページ先頭

©2009-2025 Movatter.jp