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