File tree 1 file changed +30
-0
lines changed
1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -1089,6 +1089,36 @@ 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.
1097
+
1098
+ To support Value Objects you will need to define the context option ``default_constructor_arguments ``::
1099
+
1100
+ use Symfony\Component\Serializer\Serializer;
1101
+ use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
1102
+
1103
+ class MyObj {
1104
+ private $foo;
1105
+ private $bar;
1106
+
1107
+ public function __construct($foo, $bar)
1108
+ {
1109
+ $this->foo = $foo;
1110
+ $this->bar = $bar;
1111
+ }
1112
+ }
1113
+
1114
+ $normalizer = new ObjectNormalizer($classMetadataFactory);
1115
+ $serializer = new Serializer(array($normalizer));
1116
+
1117
+ $data = $serializer->denormalize(['foo' => 'Hello'], 'MyObj', array('default_constructor_arguments' => array(
1118
+ 'MyObj' => array('foo' => '', 'bar' => ''),
1119
+ )));
1120
+ // $data = new MyObj('Hello', '');
1121
+
1092
1122
Recursive Denormalization and Type Safety
1093
1123
-----------------------------------------
1094
1124
You can’t perform that action at this time.
0 commit comments