4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Serializer\Normalizer;
14 use Symfony\Component\Serializer\SerializerAwareInterface;
15 use Symfony\Component\Serializer\SerializerAwareTrait;
18 * @author Jordi Boggiano <j.boggiano@seld.be>
20 class CustomNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface
22 use SerializerAwareTrait;
27 public function normalize($object, $format = null, array $context = array())
29 return $object->normalize($this->serializer, $format, $context);
35 public function denormalize($data, $class, $format = null, array $context = array())
37 $object = new $class();
38 $object->denormalize($this->serializer, $data, $format, $context);
44 * Checks if the given class implements the NormalizableInterface.
46 * @param mixed $data Data to normalize
47 * @param string $format The format being (de-)serialized from or into
51 public function supportsNormalization($data, $format = null)
53 return $data instanceof NormalizableInterface;
57 * Checks if the given class implements the NormalizableInterface.
59 * @param mixed $data Data to denormalize from
60 * @param string $type The class to which the data should be denormalized
61 * @param string $format The format being deserialized from
65 public function supportsDenormalization($data, $type, $format = null)
67 if (!class_exists($type)) {
71 return is_subclass_of($type, 'Symfony\Component\Serializer\Normalizer\DenormalizableInterface');