@@ -1089,18 +1089,18 @@ These are the options available:
1089
1089
``remove_empty_tags ``
1090
1090
If set to true, removes all empty tags in the generated XML.
1091
1091
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
+ ------------------------------
1097
1094
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::
1099
1098
1100
1099
use Symfony\Component\Serializer\Serializer;
1101
1100
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
1102
1101
1103
- class MyObj {
1102
+ class MyObj
1103
+ {
1104
1104
private $foo;
1105
1105
private $bar;
1106
1106
@@ -1114,9 +1114,13 @@ To support Value Objects you will need to define the context option ``default_co
1114
1114
$normalizer = new ObjectNormalizer($classMetadataFactory);
1115
1115
$serializer = new Serializer(array($normalizer));
1116
1116
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
+ ));
1120
1124
// $data = new MyObj('Hello', '');
1121
1125
1122
1126
Recursive Denormalization and Type Safety
@@ -1302,3 +1306,4 @@ Learn more
1302
1306
.. _YAML : http://yaml.org/
1303
1307
.. _CSV : https://tools.ietf.org/html/rfc4180
1304
1308
.. _`RFC 7807` : https://tools.ietf.org/html/rfc7807
1309
+ .. _`Value Objects` : https://en.wikipedia.org/wiki/Value_object
0 commit comments