From 88f7364c1ebdcdf1d12aaaecb06a26e747c2f037 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Thu, 18 Jan 2018 12:08:25 +0100 Subject: [PATCH] Minor improvements in the new abstract serializer doc --- components/serializer.rst | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/components/serializer.rst b/components/serializer.rst index b11a3a592a2..9cb9cc76e86 100644 --- a/components/serializer.rst +++ b/components/serializer.rst @@ -988,7 +988,7 @@ Serializing Interfaces and Abstract Classes When dealing with objects that are fairly similar or share properties, you may use interfaces or abstract classes. The Serializer component allows you to -serialize and deserialize these objects using a *"discrimator class mapping"*. +serialize and deserialize these objects using a *"discriminator class mapping"*. The discriminator is the field (in the serialized string) used to differentiate between the possible objects. In practice, when using the Serializer component, @@ -999,6 +999,13 @@ Consider an application that defines an abstract ``CodeRepository`` class extended by ``GitHubCodeRepository`` and ``BitBucketCodeRepository`` classes. This example shows how to serialize and deserialize those objects:: + // ... + use Symfony\Component\Serializer\Encoder\JsonEncoder; + use Symfony\Component\Serializer\Mapping\ClassDiscriminatorMapping; + use Symfony\Component\Serializer\Mapping\ClassDiscriminatorResolver; + use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; + use Symfony\Component\Serializer\Serializer; + $discriminator = new ClassDiscriminatorResolver(); $discriminator->addClassMapping(CodeRepository::class, new ClassDiscriminatorMapping('type', [ 'github' => GitHubCodeRepository::class,