File tree 1 file changed +7
-3
lines changed
1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -170,9 +170,10 @@ needs three parameters:
170
170
in Symfony 3.3.
171
171
172
172
By default, additional attributes that are not mapped to the denormalized
173
- object will be ignored by the Serializer component. Set the ``allow_extra_attributes ``
174
- key of the deserialization context to ``false `` to let the serializer throw
175
- an exception when additional attributes are passed::
173
+ object will be ignored by the Serializer component. Include a
174
+ ClassMetadataFactory when constructing the normalizer and set the
175
+ ``allow_extra_attributes `` key of the deserialization context to ``false `` to
176
+ let the serializer throw an exception when additional attributes are passed::
176
177
177
178
$data = <<<EOF
178
179
<person>
@@ -184,6 +185,9 @@ an exception when additional attributes are passed::
184
185
185
186
// this will throw a Symfony\Component\Serializer\Exception\ExtraAttributesException
186
187
// because "city" is not an attribute of the Person class
188
+ $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
189
+ $normalizer = new ObjectNormalizer($classMetadataFactory);
190
+ $serializer = new Serializer(array($normalizer));
187
191
$person = $serializer->deserialize($data, 'Acme\Person', 'xml', array(
188
192
'allow_extra_attributes' => false,
189
193
));
You can’t perform that action at this time.
0 commit comments