File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -170,9 +170,10 @@ needs three parameters:
170170 in Symfony 3.3.
171171
172172By 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::
176177
177178 $data = <<<EOF
178179 <person>
@@ -184,6 +185,9 @@ an exception when additional attributes are passed::
184185
185186 // this will throw a Symfony\Component\Serializer\Exception\ExtraAttributesException
186187 // 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));
187191 $person = $serializer->deserialize($data, 'Acme\Person', 'xml', array(
188192 'allow_extra_attributes' => false,
189193 ));
You can’t perform that action at this time.
0 commit comments