8000 feature #6975 [Serializer] documentation for allow_extra_attributes (… · symfony/symfony-docs@f156216 · GitHub
[go: up one dir, main page]

Skip to content

Commit f156216

Browse files
committed
feature #6975 [Serializer] documentation for allow_extra_attributes (juliendidier)
This PR was merged into the master branch. Discussion ---------- [Serializer] documentation for allow_extra_attributes Doc PR for [symfony/symfony#19958](symfony/symfony#19958) Commits ------- 28dcc94 [Serializer] documentation for allow_extra_attributes
2 parents 09b1a22 + 28dcc94 commit f156216

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

components/serializer.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,26 @@ needs three parameters:
152152
#. The name of the class this information will be decoded to
153153
#. The encoder used to convert that information into an array
154154

155+
By default, additional attributes that are not mapped to the denormalized object will be ignored
156+
by the Serializer component. Set the ``allow_extra_attributes`` key of the deserialization context to ``false``
157+
to let the serializer throw an exception when additional attributes are passed.
158+
159+
This will throw an :class:`Symfony\\Component\\Serializer\\Exception\\ExtraAttributesException` exception,
160+
because city is not an attribute of the ``Person`` class::
161+
162+
$data = <<<EOF
163+
<person>
164+
<name>foo</name>
165+
<age>99</age>
166+
<city>Paris</city>
167+
</person>
168+
EOF;
169+
170+
$person = $serializer->deserialize($data, 'Acme\Person', 'xml', array(
171+
'allow_extra_attributes' => false,
172+
));
173+
174+
155175
Deserializing in an Existing Object
156176
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
157177

0 commit comments

Comments
 (0)
0