**Symfony version(s) affected**: 4.4.4 **Description** <!-- A clear and concise description of the problem. --> **How to reproduce** ```php <?php require __DIR__ . '/vendor/autoload.php'; $data = [ 'item' => [ '@attr' => null, ], ]; $encoder = new \Symfony\Component\Serializer\Encoder\XmlEncoder('some-context'); echo $encoder->encode($data, 'xml', ['xml_format_output' => true]); ``` **Possible Solution** Add a null check [here](https://github.com/symfony/serializer/blob/4.4/Encoder/XmlEncoder.php#L420)