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

Commita81b7bf

Browse files
Minor reword
1 parent844154e commita81b7bf

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

‎components/serializer.rst‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -913,18 +913,18 @@ These are the options available:
913913
``remove_empty_tags``
914914
If set to true, removes all empty tags in the generated XML.
915915

916-
Handling Value Objects
917-
----------------------
918-
919-
Value Objets are difficult to handle because they often require parameters in the constructor. If the input omit one
920-
of theses parameters the serializer will throw an exception because it can't create the object.
916+
Handling Constructor Arguments
917+
------------------------------
921918

922-
To support Value Objects you will need to define the context option ``default_constructor_arguments``::
919+
If the constructor of a class defines arguments, as usually happens with
920+
`Value Objects`_, the serializer won't be able to create the object. In those
921+
cases, use the ``default_constructor_arguments`` context option::
923922

924923
use Symfony\Component\Serializer\Serializer;
925924
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
926925

927-
class MyObj {
926+
class MyObj
927+
{
928928
private $foo;
929929
private $bar;
930930

@@ -938,9 +938,13 @@ To support Value Objects you will need to define the context option ``default_co
938938
$normalizer = new ObjectNormalizer($classMetadataFactory);
939939
$serializer = new Serializer(array($normalizer));
940940

941-
$data = $serializer->denormalize(['foo' => 'Hello'], 'MyObj', array('default_constructor_arguments' => array(
942-
'MyObj' => array('foo' => '', 'bar' => ''),
943-
)));
941+
$data = $serializer->denormalize(
942+
array('foo' => 'Hello'),
943+
'MyObj',
944+
array('default_constructor_arguments' => array(
945+
'MyObj' => array('foo' => '', 'bar' => ''),
946+
)
947+
));
944948
// $data = new MyObj('Hello', '');
945949

946950
Recursive Denormalization and Type Safety
@@ -1116,3 +1120,4 @@ Learn more
11161120
.. _XML:https://www.w3.org/XML/
11171121
.. _YAML:http://yaml.org/
11181122
.. _CSV:https://tools.ietf.org/html/rfc4180
1123+
.. _`Value Objects`:https://en.wikipedia.org/wiki/Value_object

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp