@@ -245,23 +245,32 @@ The definition of serialization can be specified using annotations, XML
245245or YAML. The :class: `Symfony\\ Component\\ Serializer\\ Mapping\\ Factory\\ ClassMetadataFactory `
246246that will be used by the normalizer must be aware of the format to use.
247247
248- Initialize the :class: `Symfony\\ Component\\ Serializer\\ Mapping\\ Factory\\ ClassMetadataFactory `
249- like the following: :
248+ The following code shows how to initialize the :class: `Symfony\\ Component\\ Serializer\\ Mapping\\ Factory\\ ClassMetadataFactory `
249+ for each format :
250250
251- use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
252- // For annotations
253- use Doctrine\Common\Annotations\AnnotationReader;
254- use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
255- // For XML
256- // use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader;
257- // For YAML
258- // use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader;
251+ .. configuration-block ::
259252
260- $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
261- // For XML
262- // $classMetadataFactory = new ClassMetadataFactory(new XmlFileLoader('/path/to/your/definition.xml'));
263- // For YAML
264- // $classMetadataFactory = new ClassMetadataFactory(new YamlFileLoader('/path/to/your/definition.yaml'));
253+ .. code-block :: php-annotations
254+
255+ use Doctrine\Common\Annotations\AnnotationReader;
256+ use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
257+ use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
258+
259+ $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
260+
261+ .. code-block :: yaml
262+
263+ use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
264+ use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader;
265+
266+ $classMetadataFactory = new ClassMetadataFactory(new YamlFileLoader('/path/to/your/definition.yaml'));
267+
268+ .. code-block :: xml
269+
270+ use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
271+ use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader;
272+
273+ $classMetadataFactory = new ClassMetadataFactory(new XmlFileLoader('/path/to/your/definition.xml'));
265274
266275 .. _component-serializer-attributes-groups-annotations :
267276
@@ -966,10 +975,10 @@ Here, we set it to 2 for the ``$child`` property:
966975
967976 .. code-block :: php-annotations
968977
969- use Symfony\Component\Serializer\Annotation\MaxDepth;
970-
971978 namespace Acme;
972979
980+ use Symfony\Component\Serializer\Annotation\MaxDepth;
981+
973982 class MyObj
974983 {
975984 /**
@@ -1233,13 +1242,13 @@ When using the component standalone, an implementation of :class:`Symfony\\Compo
12331242(usually an instance of :class: `Symfony\\ Component\\ PropertyInfo\\ PropertyInfoExtractor `) must be passed as the 4th
12341243parameter of the ``ObjectNormalizer ``::
12351244
1245+ namespace Acme;
1246+
12361247 use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
12371248 use Symfony\Component\Serializer\Serializer;
12381249 use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
12391250 use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
12401251
1241- namespace Acme;
1242-
12431252 class ObjectOuter
12441253 {
12451254 private $inner;
0 commit comments