Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9e6cab0

Browse 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

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)