diff --git a/serializer/encoders.rst b/serializer/encoders.rst index c3fb2e26b50..3087dcaddd4 100644 --- a/serializer/encoders.rst +++ b/serializer/encoders.rst @@ -211,6 +211,8 @@ These are the options available on the :ref:`serializer context `` nodes. .. versionadded:: 7.1 @@ -224,6 +226,8 @@ These are the options available on the :ref:`serializer context 2019-10-24 // +Example with ``preserve_numeric_keys``:: + + use Symfony\Component\Serializer\Encoder\XmlEncoder; + + $data = [ + 'person' => [ + ['firstname' => 'Benjamin', 'lastname' => 'Alexandre'], + ['firstname' => 'Damien', 'lastname' => 'Clay'], + ], + ]; + + $xmlEncoder->encode($data, 'xml', ['preserve_numeric_keys' => false]); + // outputs: + // + // + // Benjamin + // Alexandre + // + // + // Damien + // Clay + // + // + $xmlEncoder->encode($data, 'xml', ['preserve_numeric_keys' => true]); + // outputs: + // + // + // + // Benjamin + // Alexandre + // + // + // Damien + // Clay + // + // + // + The ``YamlEncoder`` -------------------