Skip to content

Unable to use serializer component #7145

Closed
@biruwon

Description

@biruwon

I'm following this doc: http://symfony.com/doc/2.0/components/serializer.html

The Serializer is on my vendors under Symfony/Component/Directory.

I create a new Serializer:

use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;

$encoders = array(new XmlEncoder(), new JsonEncoder());
$normalizers = array(new GetSetMethodNormalizer());

$serializer = new Serializer($normalizers, $encoders);

And then serialize my document(I'm using Doctrine MongoDB ODM):

$serializer->serialize($myDocument, 'json');

But I get this error:

UnexpectedValueException: Serialization for the format json is not supported

The same problem using xml

And when I try to use another way to initialize the serializer using services:

$s = $this->container->get('serializer');
$json = $s->serialize($object, 'json');

Get this error:

ServiceNotFoundException: You have requested a non-existent service "serializer".

I'm using Symfony2.0.20

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions