Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit33262be

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 ClassMetadataFactorySymfony PR atsymfony/symfony#26534Commits-------bc011c0 Rewordb05c1cc Codefence ClassMetadataFactorya4cb67a Document the required ClassMetadataFactory
2 parents435566d +bc011c0 commit33262be

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)

[8]ページ先頭

©2009-2025 Movatter.jp