Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.3k
Add new serializer empty_data feature doc#8914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1089,6 +1089,41 @@ These are the options available: | ||
| ``remove_empty_tags`` | ||
| If set to true, removes all empty tags in the generated XML. | ||
| Handling Constructor Arguments | ||
| ------------------------------ | ||
| If the constructor of a class defines arguments, as usually happens with | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. It's not exact: the serializer deals well with constructor arguments, if they are present in the data to deserialize. The | ||
| `Value Objects`_, the serializer won't be able to create the object if some | ||
| arguments are missing. In those cases, use the ``default_constructor_arguments`` | ||
| context option:: | ||
| use Symfony\Component\Serializer\Serializer; | ||
| use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; | ||
| class MyObj | ||
| { | ||
| private $foo; | ||
| private $bar; | ||
| public function __construct($foo, $bar) | ||
| { | ||
| $this->foo = $foo; | ||
| $this->bar = $bar; | ||
| } | ||
| } | ||
| $normalizer = new ObjectNormalizer($classMetadataFactory); | ||
| $serializer = new Serializer(array($normalizer)); | ||
| $data = $serializer->denormalize( | ||
| array('foo' => 'Hello'), | ||
| 'MyObj', | ||
| array('default_constructor_arguments' => array( | ||
| 'MyObj' => array('foo' => '', 'bar' => ''), | ||
| ) | ||
| )); | ||
| // $data = new MyObj('Hello', ''); | ||
| Recursive Denormalization and Type Safety | ||
| ----------------------------------------- | ||
| @@ -1272,3 +1307,4 @@ Learn more | ||
| .. _YAML: http://yaml.org/ | ||
| .. _CSV: https://tools.ietf.org/html/rfc4180 | ||
| .. _`RFC 7807`: https://tools.ietf.org/html/rfc7807 | ||
| .. _`Value Objects`: https://en.wikipedia.org/wiki/Value_object | ||