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';
23 protected $encodingImpl;
24 protected $decodingImpl;
26 public function __construct(JsonEncode $encodingImpl = null, JsonDecode $decodingImpl = null)
28 $this->encodingImpl = $encodingImpl ?: new JsonEncode();
29 $this->decodingImpl = $decodingImpl ?: new JsonDecode(true);
35 public function encode($data, $format, array $context = array())
37 return $this->encodingImpl->encode($data, self::FORMAT, $context);
43 public function decode($data, $format, array $context = array())
45 return $this->decodingImpl->decode($data, self::FORMAT, $context);
51 public function supportsEncoding($format)
53 return self::FORMAT === $format;
59 public function supportsDecoding($format)
61 return self::FORMAT === $format;