Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions components/serializer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,11 @@ needs three parameters:
Support for the ``allow_extra_attributes`` key in the context was introduced
in Symfony 3.3.

By default, additional attributes that are not mapped to the denormalized
object will be ignored by the Serializer component. Set the ``allow_extra_attributes``
key of the deserialization context to ``false`` to let the serializer throw
an exception when additional attributes are passed::
By default, additional attributes that are not mapped to the denormalized object
will be ignored by the Serializer component. If you prefer to throw an exception
when this happens, set the ``allow_extra_attributes`` context option to
``false`` and provide an object that implements ``ClassMetadataFactoryInterface`
when constructing the normalizer::

$data = <<<EOF
<person>
Expand All @@ -184,6 +185,9 @@ an exception when additional attributes are passed::

// this will throw a Symfony\Component\Serializer\Exception\ExtraAttributesException
// because "city" is not an attribute of the Person class
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
$normalizer = new ObjectNormalizer($classMetadataFactory);
$serializer = new Serializer(array($normalizer));
$person = $serializer->deserialize($data, 'Acme\Person', 'xml', array(
'allow_extra_attributes' => false,
));
Expand Down