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

Appearance settings

Commit b0d3fe8

Browse filesBrowse files
javiereguiluzNek-
authored andcommitted
Minor reword
1 parent 5a48201 commit b0d3fe8
Copy full SHA for b0d3fe8

File tree

1 file changed

+15
-10
lines changed
Filter options

1 file changed

+15
-10
lines changed

‎components/serializer.rst

Copy file name to clipboardExpand all lines: components/serializer.rst
+15-10Lines 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
@@ -1302,3 +1306,4 @@ Learn more
13021306
.. _YAML: http://yaml.org/
13031307
.. _CSV: https://tools.ietf.org/html/rfc4180
13041308
.. _`RFC 7807`: https://tools.ietf.org/html/rfc7807
1309+
.. _`Value Objects`: https://en.wikipedia.org/wiki/Value_object

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.