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

Commit6349bd3

Browse files
authored
[Serializer] Add an option to skip null values
1 parent8213714 commit6349bd3

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎components/serializer.rst‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,25 @@ This encoder requires the :doc:`Yaml Component </components/yaml>` and
754754
transforms from and to Yaml.
755755

756756

757+
Skipping ``null`` Values
758+
------------------------
759+
760+
By default, the Serializer will preserve properties containing a ``null`` value.
761+
You can change this behavior by setting the ``skip_null_values`` context option
762+
to ``true``::
763+
764+
$dummy = new class {
765+
public $foo;
766+
public $bar = 'notNull';
767+
};
768+
769+
$normalizer = new ObjectNormalizer();
770+
$result = $normalizer->normalize($dummy, 'json', ['skip_null_values' => true]);
771+
// ['bar' => 'notNull']
772+
773+
..versionadded::4.2
774+
The ``skip_null_values`` option was introduced in Symfony 4.2.
775+
757776
.. _component-serializer-handling-circular-references:
758777

759778
Handling Circular References

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp