@@ -85,21 +85,37 @@ you need it or it can be used in a controller::
85
85
Adding Normalizers and Encoders
86
86
-------------------------------
87
87
88
- Once enabled, the ``serializer `` service will be available in the container
89
- and will be loaded with four :ref: `encoders <component-serializer-encoders >`
90
- (:class: `Symfony\\ Component\\ Serializer\\ Encoder\\ JsonEncoder `,
91
- :class: `Symfony\\ Component\\ Serializer\\ Encoder\\ XmlEncoder `,
92
- :class: `Symfony\\ Component\\ Serializer\\ Encoder\\ YamlEncoder `, and
93
- :class: `Symfony\\ Component\\ Serializer\\ Encoder\\ CsvEncoder `) and the
94
- :ref: `ObjectNormalizer normalizer <component-serializer-normalizers >`.
95
-
96
- You can load normalizers and/or encoders by tagging them as
88
+ Once enabled, the ``serializer `` service will be available in the container.
89
+ It comes with a set of useful :ref: `encoders <component-serializer-encoders >`
90
+ and :ref: `normalizers <component-serializer-normalizers >`.
91
+
92
+ Encoders supporting the following formats are enabled:
93
+
94
+ * JSON: :class: `Symfony\\ Component\\ Serializer\\ Encoder\\ JsonEncoder `
95
+ * XML: :class: `Symfony\\ Component\\ Serializer\\ Encoder\\ XmlEncoder `
96
+
97
+ As well as the following normalizers:
98
+
99
+ * :class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ ObjectNormalizer ` to
100
+ handle typical data objects
101
+ * :class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ DateTimeNormalizer ` for
102
+ objects implementing the :class: `DateTimeInterface ` interface
103
+ * :class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ DataUriNormalizer ` to
104
+ transform :class: `SplFileInfo ` objects in `Data URIs `_
105
+ * :class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ JsonSerializableNormalizer `
106
+ to deal with objects implementing the :class: `JsonSerializable ` interface
107
+ * :class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ ArrayDenormalizer ` to
108
+ denormalize arrays of objects using a format like `MyObject[] ` (note the `[] ` suffix)
109
+
110
+ Custom normalizers and/or encoders can also be loaded by tagging them as
97
111
:ref: `serializer.normalizer <reference-dic-tags-serializer-normalizer >` and
98
112
:ref: `serializer.encoder <reference-dic-tags-serializer-encoder >`. It's also
99
113
possible to set the priority of the tag in order to decide the matching order.
100
114
101
115
Here is an example on how to load the
102
- :class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ GetSetMethodNormalizer `:
116
+ :class: `Symfony\\ Component\\ Serializer\\ Normalizer\\ GetSetMethodNormalizer `, a
117
+ faster alternative to the `ObjectNormalizer ` when data objects always use
118
+ getters and setters:
103
119
104
120
.. configuration-block ::
105
121
@@ -310,3 +326,4 @@ take a look at how this bundle works.
310
326
.. _`ApiPlatform` : https://github.com/api-platform/core
311
327
.. _`JSON-LD` : http://json-ld.org
312
328
.. _`Hydra Core Vocabulary` : http://hydra-cg.com
329
+ .. _`Data URIs` : https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
0 commit comments