title: Symfony Serializer doesn't deserialize into objects in different namespace: 'no supporting normalizer found'
body: <p>I'm trying to deserialize json into an object using the packages symfony/serializer and symfony/property-access through composer. It works when the class I'm deserializing into is in the same file, but not when it's somewhere else (not even a different file in the same namespace).
  I have the following code:</p>
  
  <pre><code>&lt;?php // Somewhere/Foo.php
  namespace Somewhere;
  class Foo
  {
      private $foo;
      public function getFoo() { return $this-&gt;foo; }
      public function setFoo($foo) { $this-&gt;foo = $foo; }
  }
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>&lt;?php // file tests/Test.php
  namespace tests;
  
  use Symfony\Component\Serializer\Encoder\JsonEncoder;
  use Symfony\Component\Serializer\Encoder\XmlEncoder;
  use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
  use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
  use Symfony\Component\Serializer\Serializer;
  use Somewhere\Foo;
  
  class Foo2
  {
      private $foo;
      public function getFoo() { return $this-&gt;foo; }
      public function setFoo($foo) { $this-&gt;foo = $foo; }
  }
  
  class Test extends \PHPUnit_Framework_TestCase
  {
  
      public function testFoo()
      {
          $encoders = array(new XmlEncoder(), new JsonEncoder());
          $normalizers = array(new ObjectNormalizer(), new GetSetMethodNormalizer());
          $serializer = new Serializer($normalizers, $encoders);
          $payload = '{"foo": {"bar": "baz"}}';
  
          $obj = $serializer-&gt;deserialize($payload, Foo::class, 'json');
          $this-&gt;assertInstanceOf(Foo::class, $obj);
      }
  
      public function testFoo2()
      {
          $encoders = array(new XmlEncoder(), new JsonEncoder());
          $normalizers = array(new ObjectNormalizer(), new GetSetMethodNormalizer());
          $serializer = new Serializer($normalizers, $encoders);
          $payload = '{"foo": {"bar": "baz"}}';
  
          $obj = $serializer-&gt;deserialize($payload, Foo2::class, 'json');
          $this-&gt;assertInstanceOf(Foo2::class, $obj);
      }
  }
  </code></pre>
  
  <p>The test using the local class (<code>Foo2</code>) works fine, but the one using the class in a different namespace (<code>\Somewhere\Foo</code>) shows me this error:
  <code>Symfony\Component\Serializer\Exception\UnexpectedValueException: Could not denormalize object of type Somewhere\Foo, no supporting normalizer found</code>.</p>
  
  <p>I've tried using <code>\Somewhere\Foo::class</code>, <code>'Foo'</code> and <code>'\Somewhere\Foo'</code> instead of Foo::class too without any luck.</p>
  
  <p>Similar Questions:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/31831133/serializing-and-deserializing-in-symfony">Serializing and Deserializing in Symfony</a> marks one answer which uses strings as correct but not really, if you read the comments you'll see it didn't really solved the question.</li>
  <li><a href="https://stackoverflow.com/questions/39576832/could-not-denormalize-object-of-type-no-supporting-normalizer-found-symfony-2">Could not denormalize object of type, no supporting normalizer found. Symfony 2.8</a> In the comments the OP says using <code>ClassName::class</code> worked, but this doesn't work for me.</li>
  <li><a href="https://stackoverflow.com/questions/19953802/problems-try-encode-entity-to-json">Problems try encode entity to json</a> The answer was to stop using <code>symfony/serializer</code> and use <code>jms/serializer</code> instead. Is it really not possible with Symfony's serializer?</li>
  </ul>
  
  <p>Thanks for the help</p>