8000 [Serializer] documentation for allow_extra_attributes · symfony/symfony-docs@28dcc94 · GitHub
[go: up one dir, main page]

Skip to content

Commit 28dcc94

Browse files
committed
[Serializer] documentation for allow_extra_attributes
1 parent b386600 commit 28dcc94

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
@@ -151,6 +151,26 @@ needs three parameters:
151151
#. The name of the class this information will be decoded to
152152
#. The encoder used to convert that i 8000 nformation into an array
153153

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

0 commit comments

Comments
 (0)
0