title: Symfony 3.2 binding post values to form in REST api
body: <p>I use following libraries/technologies:</p>
  
  <p>JMSSerializer, FOSRestBundle + Symfony 3.2 + PHP 7.1</p>
  
  <p>When I try to make POST request to my POST endpoint I can't get form to work. </p>
  
  <p>Files:</p>
  
  <p>Country.php -> POPO Entity</p>
  
  <p>CountryType.php</p>
  
  <pre><code>&lt;?php
  
  declare(strict_types = 1);
  namespace AppBundle\Form;
  
  use AppBundle\Model\Entity\Country;
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  use Symfony\Component\Form\Extension\Core\Type\TextType;
  use Symfony\Component\Form\FormBuilderInterface;
  use Symfony\Component\OptionsResolver\OptionsResolver;
  
  class CountryType extends AbstractType
  {
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder-&gt;add('name' , TextType::class)
              -&gt;add('iso_alpha_2_code', TextType::class)
              -&gt;add('iso_alpha_3_code', TextType::class)
              -&gt;add('is_numeric_code', IntegerType::class);
      }
  
      public function configureOptions(OptionsResolver $resolver)
      {
          $resolver-&gt;setDefaults([
              'data_class' =&gt; Country::class,
              'csrf_protection' =&gt; false,
          ]);
      }
  
      /**
       * @inheritdoc
       */
      public function getName() : string
      {
          return '';
      }
  }
  </code></pre>
  
  <p>CountryController.php postAction</p>
  
  <pre><code>public function postAction(Request $request)
      {
          $country = new Country();
          $form = $this-&gt;createForm(CountryType::class,  $country);
          $form-&gt;handleRequest($request);
  
          if ($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()) {
              die('ok');
              // TODO INSERT DATA then redirect
              return $this-&gt;routeRedirectView('get_country', ['id' =&gt; $country-&gt;getId()]);
          }
  
          return $this-&gt;get('fos_rest.view_handler')-&gt;handle(View::create($form));
      }
  </code></pre>
  
  <p>The problem is that it doesn't enter if block because both isSubmited() and isValid() methods return false. When I call <code>$form-&gt;getData()</code> it returns</p>
  
  <p><code>
  CountryController.php on line 40:
  Country {#306
    -id: null
    -name: null
    -isoAlpha2Code: null
    -isoAlpha3Code: null
    -isNumericCode: null
  }
  </code></p>
  
  <p>The request I make:</p>
  
  <p><a href="https://i.stack.imgur.com/1miqD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1miqD.png" alt="Request to API"></a></p>
  
  <p>Could you give me a tip what I do wrong? </p>