@@ -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
946950Recursive 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