diff --git a/components/serializer.rst b/components/serializer.rst index 084879532f8..6f28e5649ff 100644 --- a/components/serializer.rst +++ b/components/serializer.rst @@ -754,6 +754,25 @@ This encoder requires the :doc:`Yaml Component ` and transforms from and to Yaml. +Skipping ``null`` Values +------------------------ + +By default, the Serializer will preserve properties containing a ``null`` value. +You can change this behavior by setting the ``skip_null_values`` context option +to ``true``:: + + $dummy = new class { + public $foo; + public $bar = 'notNull'; + }; + + $normalizer = new ObjectNormalizer(); + $result = $normalizer->normalize($dummy, 'json', ['skip_null_values' => true]); + // ['bar' => 'notNull'] + +.. versionadded:: 4.2 + The ``skip_null_values`` option was introduced in Symfony 4.2. + .. _component-serializer-handling-circular-references: Handling Circular References