-
Notifications
You must be signed in to change notification settings - Fork 3
Serializing
BowlOfSoup edited this page Sep 16, 2020
·
3 revisions
Serializing will transform an object, class or array of data into another format, for example: JSON or XML. You can serialize an associative array with plain data, an array of class, or a single class.
If you want to normalize an object/class it will normalize those object/classes first, the "Normalize" annotations are used. See Normalizing for details on that.
For serialization two encodings are supported: JSON and XML.
On top of the object you want to serialize:
use BowlOfSoup\NormalizerBundle\Annotation as Bos;
The serializer can be injected, but also auto-wired.
<argument type="service" id="bos.serializer" />
Calling the serializer with a group is optional, but certainly recommended.
$result = $this->serializer->serialize($someEntity, EncoderFactory::TYPE_JSON, some-optional-group');
The result will be a string of data.
See Serialize annotations for custom options.