@@ -103,6 +103,22 @@ The first parameter of the :method:`Symfony\\Component\\Serializer\\Serializer::
103
103
is the object to be serialized and the second is used to choose the proper encoder,
104
104
in this case :class: `Symfony\\ Component\\ Serializer\\ Encoder\\ JsonEncoder `.
105
105
106
+ As an option, there's a way to ignore attributes from the origin object to be
107
+ serialized, to remove those attributes use
108
+ :method: `Symfony\\ Component\\ Serializer\\ Normalizer\\ GetSetMethodNormalizer::setIgnoredAttributes `
109
+ method on normalizer definition::
110
+
111
+ use Symfony\Component\Serializer\Serializer;
112
+ use Symfony\Component\Serializer\Encoder\JsonEncoder;
113
+ use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
114
+
115
+ $normalizer = new GetSetMethodNormalizer();
116
+ $normalizer->setIgnoredAttributes(array('age'));
117
+ $encoder = new JsonEncoder();
118
+
119
+ $serializer = new Serializer(array($normalizer), array($encoder));
120
+ $serializer->serialize($person, 'json'); // Output: {"name":"foo"}
121
+
106
122
Deserializing an Object
107
123
~~~~~~~~~~~~~~~~~~~~~~~
108
124
@@ -125,6 +141,32 @@ needs three parameters:
125
141
2. The name of the class this information will be decoded to
126
142
3. The encoder used to convert that information into an array
127
143
144
+ Sometimes property names from the serialized content are underscored, in a
145
+ regular configuration those attributes will use get/set methods as
146
+ ``getCamel_case ``, when ``getCamelCase `` method is preferable. To change that
147
+ behavior use
148
+ :method: `Symfony\\ Component\\ Serializer\\ Normalizer\\ GetSetMethodNormalizer::setCamelizedAttributes `
149
+ on normalizer definition::
150
+
151
+ $encoder = new JsonEncoder();
152
+ $normalizer = new GetSetMethodNormalizer();
153
+ $normalizer->setCamelizedAttributes(array('camel_case'));
154
+
155
+ $serializer = new Serializer(array($normalizer), array($encoder));
156
+
157
+ $json = <<<EOT
158
+ {
159
+ "name": "foo",
160
+ "age": "19",
161
+ "camel_case": "bar"
162
+ }
163
+ EOT;
164
+
165
+ $person = $serializer->deserialize($json, 'Acme\Person', 'json');
166
+
167
+ As a final result, Person object uses ``camelCase `` attribute for
168
+ ``camel_case `` json parameter, the same applies on getters and setters.
169
+
128
170
JMSSerializer
129
171
-------------
130
172
0 commit comments