Skip to content

Commit 33262be

Browse files
committed
minor #9948 Document the required ClassMetadataFactory (deviantintegral, javiereguiluz)
This PR was submitted for the master branch but it was merged into the 3.4 branch instead (closes #9948). Discussion ---------- Document the required ClassMetadataFactory Symfony PR at symfony/symfony#26534 Commits ------- bc011c0 Reword b05c1cc Codefence ClassMetadataFactory a4cb67a Document the required ClassMetadataFactory
2 parents 435566d + bc011c0 commit 33262be

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

components/serializer.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,11 @@ needs three parameters:
169169
Support for the ``allow_extra_attributes`` key in the context was introduced
170170
in Symfony 3.3.
171171

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::
172+
By default, additional attributes that are not mapped to the denormalized object
173+
will be ignored by the Serializer component. If you prefer to throw an exception
174+
when this happens, set the ``allow_extra_attributes`` context option to
175+
``false`` and provide an object that implements ``ClassMetadataFactoryInterface`
176+
when constructing the normalizer::
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
));

0 commit comments

Comments
 (0)