Symfony serializer groups

Code
<?php

use Symfony\Component\Serializer\Serializer;
use 
Symfony\Component\Serializer\Encoder\XmlEncoder;
use 
Symfony\Component\Serializer\Normalizer\ObjectNormalizer;

use 
Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
use 
Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
use 
Doctrine\Common\Annotations\AnnotationReader;
use 
Symfony\Component\Serializer\Annotation\Groups;

$xmlEncoder = new XmlEncoder('rootNode');

// Enable annotations for serializer
$classMetadataFactory = new ClassMetadataFactory(
    new 
AnnotationLoader(new AnnotationReader())
);
$normalizer = new ObjectNormalizer($classMetadataFactory);

$serializer = new Serializer([$normalizer], [$xmlEncoder]);

$object = new class() {

    public 
$foo 1;
    
    
/**
     * @Groups({"text_only"})
     */
    
public $bar 'text';
    
    public 
$qux null;
};

$serialized $serializer->encode($object'xml');
echo 
htmlentities($serialized) . PHP_EOL;

$serialized $serializer->encode($object'xml', ['groups' => ['text_only']]);
echo 
htmlentities($serialized);
Result
<?xml version="1.0"?>
<rootNode><foo>1</foo><bar>text</bar><qux/></rootNode>

<?xml version="1.0"?>
<rootNode><bar>text</bar></rootNode>
Used Versions
PHP 7.1, Zend 3.0, Symfony 3.2, Laravel 5.2, PHPUnit 5.6, Doctrine 2.6