@@ -245,23 +245,32 @@ The definition of serialization can be specified using annotations, XML
245
245
or YAML. The :class: `Symfony\\ Component\\ Serializer\\ Mapping\\ Factory\\ ClassMetadataFactory `
246
246
that will be used by the normalizer must be aware of the format to use.
247
247
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 :
250
250
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 ::
259
252
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'));
265
274
266
275
.. _component-serializer-attributes-groups-annotations :
267
276
@@ -966,10 +975,10 @@ Here, we set it to 2 for the ``$child`` property:
966
975
967
976
.. code-block :: php-annotations
968
977
969
- use Symfony\Component\Serializer\Annotation\MaxDepth;
970
-
971
978
namespace Acme;
972
979
980
+ use Symfony\Component\Serializer\Annotation\MaxDepth;
981
+
973
982
class MyObj
974
983
{
975
984
/**
@@ -1233,13 +1242,13 @@ When using the component standalone, an implementation of :class:`Symfony\\Compo
1233
1242
(usually an instance of :class: `Symfony\\ Component\\ PropertyInfo\\ PropertyInfoExtractor `) must be passed as the 4th
1234
1243
parameter of the ``ObjectNormalizer ``::
1235
1244
1245
+ namespace Acme;
1246
+
1236
1247
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
1237
1248
use Symfony\Component\Serializer\Serializer;
1238
1249
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
1239
1250
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
1240
1251
1241
- namespace Acme;
1242
-
1243
1252
class ObjectOuter
1244
1253
{
1245
1254
private $inner;
0 commit comments