File tree 1 file changed +22
-0
lines changed
1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -151,6 +151,28 @@ needs three parameters:
151
151
#. The name of the class this information will be decoded to
152
152
#. The encoder used to convert that information into an array
153
153
154
+ Extra attributes, attributes which are not mapped to the object, are allowed per default
155
+ by the serializer.
156
+ :method: `Symfony\\ Component\\ Serializer\\ Serializer::deserialize `
157
+ has a fourth parameter, the context. If you want to throw an exception if an attribute is outside
158
+ the object scope, use ``allow_extra_attributes `` as ``false ``.
159
+
160
+ This will throws a :class: `Symfony\C omponent\S erializer\E xception\E xtraAttributesException ` exception,
161
+ because city is not an attribute of ``Acme\Person ``::
162
+
163
+ $data = <<<EOF
164
+ <person>
165
+ <name>foo</name>
166
+ <age>99</age>
167
+ <city>Paris</city>
168
+ </person>
169
+ EOF;
170
+
171
+ $person = $serializer->deserialize($data, 'Acme\Person', 'xml', array(
172
+ 'allow_extra_attributes' => false,
173
+ ));
174
+
175
+
154
176
Deserializing in an Existing Object
155
177
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
156
178
You can’t perform that action at this time.
0 commit comments