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

Appearance settings

Commit 9e6cab0

Browse filesBrowse files
committed
minor #10427 [Serializer] Add an option to skip null values (dunglas)
This PR was merged into the master branch. Discussion ---------- [Serializer] Add an option to skip null values symfony/symfony#28661 Commits ------- 6349bd3 [Serializer] Add an option to skip null values
2 parents 8213714 + 6349bd3 commit 9e6cab0
Copy full SHA for 9e6cab0

File tree

1 file changed

+19
-0
lines changed
Filter options

1 file changed

+19
-0
lines changed

‎components/serializer.rst

Copy file name to clipboardExpand all lines: components/serializer.rst
+19Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.