How to convert Serializer annotations to YML or XML configuration?

We’ve been tasked with converting all the serialization annotations in our classes to dedicated configuration classes.

There are a few dozen classes in this application, with at around 20 of them with custom annotations for the serializer (with the rest being serialized without the need of any custom configuration).

Is there a way to produce configuration files (XML preferred, but YAML acceptable) from the existing serializer configuration?

For example, starting from these annotations:

namespace Acme;

use SymfonyComponentSerializerAnnotationGroups;

class MyObj
     * @Groups({"group1", "group2"})
     * @MaxDepth(2)
    public $foo;

     * @Groups("group3")
     * @SerializedName("bar_name")
    public function getBar() 
        return $this->bar;
// rest of the class


Generate this YAML:

            groups: ['group1', 'group2']
            max_depth: 2
            groups: ['group3']
            serialized_name: bar_name

Or this XML:

<?xml version="1.0" ?>
<serializer xmlns=""
   <class name="AcmeMyObj">
       <attribute name="foo" max-depth="2">

        <attribute name="bar" serialized-name="bar_name">

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *