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

Commit73b5928

Browse files
javiereguiluzNek-
authored andcommitted
Minor reword
1 parent23a0942 commit73b5928

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
@@ -1089,18 +1089,18 @@ These are the options available:
10891089
``remove_empty_tags``
10901090
If set to true, removes all empty tags in the generated XML.
10911091

1092-
Handling Value Objects
1093-
----------------------
1094-
1095-
Value Objets are difficult to handle because they often require parameters in the constructor. If the input omit one
1096-
of theses parameters the serializer will throw an exception because it can't create the object.
1092+
Handling Constructor Arguments
1093+
------------------------------
10971094

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

11001099
use Symfony\Component\Serializer\Serializer;
11011100
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
11021101

1103-
class MyObj {
1102+
class MyObj
1103+
{
11041104
private $foo;
11051105
private $bar;
11061106

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

1117-
$data = $serializer->denormalize(['foo' => 'Hello'], 'MyObj', array('default_constructor_arguments' => array(
1118-
'MyObj' => array('foo' => '', 'bar' => ''),
1119-
)));
1117+
$data = $serializer->denormalize(
1118+
array('foo' => 'Hello'),
1119+
'MyObj',
1120+
array('default_constructor_arguments' => array(
1121+
'MyObj' => array('foo' => '', 'bar' => ''),
1122+
)
1123+
));
11201124
// $data = new MyObj('Hello', '');
11211125

11221126
Recursive Denormalization and Type Safety
@@ -1301,3 +1305,4 @@ Learn more
13011305
.. _YAML:http://yaml.org/
13021306
.. _CSV:https://tools.ietf.org/html/rfc4180
13031307
.. _`RFC 7807`:https://tools.ietf.org/html/rfc7807
1308+
.. _`Value Objects`:https://en.wikipedia.org/wiki/Value_object

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp