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\Encoder;
17 * @author Jordi Boggiano <j.boggiano@seld.be>
19 class JsonEncoder implements EncoderInterface, DecoderInterface
21 const FORMAT = 'json';
26 protected $encodingImpl;
31 protected $decodingImpl;
33 public function __construct(JsonEncode $encodingImpl = null, JsonDecode $decodingImpl = null)
35 $this->encodingImpl = $encodingImpl ?: new JsonEncode();
36 $this->decodingImpl = $decodingImpl ?: new JsonDecode(true);
42 public function encode($data, $format, array $context = array())
44 return $this->encodingImpl->encode($data, self::FORMAT, $context);
50 public function decode($data, $format, array $context = array())
52 return $this->decodingImpl->decode($data, self::FORMAT, $context);
58 public function supportsEncoding($format)
60 return self::FORMAT === $format;
66 public function supportsDecoding($format)
68 return self::FORMAT === $format;