File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -913,6 +913,36 @@ 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.
921+
922+ To support Value Objects you will need to define the context option ``default_constructor_arguments ``::
923+
924+ use Symfony\Component\Serializer\Serializer;
925+ use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
926+
927+ class MyObj {
928+ private $foo;
929+ private $bar;
930+
931+ public function __construct($foo, $bar)
932+ {
933+ $this->foo = $foo;
934+ $this->bar = $bar;
935+ }
936+ }
937+
938+ $normalizer = new ObjectNormalizer($classMetadataFactory);
939+ $serializer = new Serializer(array($normalizer));
940+
941+ $data = $serializer->denormalize(['foo' => 'Hello'], 'MyObj', array('default_constructor_arguments' => array(
942+ 'MyObj' => array('foo' => '', 'bar' => ''),
943+ )));
944+ // $data = new MyObj('Hello', '');
945+
916946Recursive Denormalization and Type Safety
917947-----------------------------------------
918948
You can’t perform that action at this time.
0 commit comments