Speaker: Hugo Hamon
Slides: https://speakerdeck.com/u/hhamon/p/leveraging-the-serializer-component
How it works:
- Start as an object
- Pass through as an array
- Encode to types:
- XML
- JSON
- etc...
- Deserialize, start as a type
- Pass through as an array
- Decode to an object
{images}
- NormalizerInterface normalizes objects to arrays, scalars
- Denormalizer does the reverse.
- EncoderInterface encodes data into the given format
- DecoderInterface decodes a string into PHP data
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Normalizer\GerSetMethodNormalizer;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\SerializerEncoder\XmlEncoder;
// TODO: Incomplete code
$serializer
->serialize($object, 'xml');
<response>
<id/>
<customer/>
<reference><...</reference>
<arrival>...</arrival>
<!-- ... -->
</response>
$ignore = array('id', 'customer');
// TODO: Code incomplete
$xml = '<response>...</response>';
// Convert an XML string to an array
$data = $serializer->decode($xml, 'xml');
// Convert the array to an object
$class = 'ns'
// TODO: code incomplete
{image} (not even trying. wait for slides.)
At this point, the slides are too intensive to take notes, please wait for the slides to be published.
- JMS Serializer Bundle
- Twig Helpers
- Customizing the XML root node
- Serializing an object to a single XML node
- Excluding or Exposing properties
- Managing object properties, versioning
- Offering several views of a serialized object
- Forcing the serializer to call getters & setters
- Mapping a property to another getter of setter method
- Customizing the order in which properties are serialized
- Typing properties for a complete unserialization