I'm trying to use FOSRestBundle's request body converter but my current implementation doesn't seem to work.
I am using Symfony2, Propel, AngularJS (it sends data to server)
What am i doing wrong?
config.yml:
fos_rest:
    routing_loader:
    default_format: json
    include_format:       false     
view:
    view_response_listener: force
body_listener: true
param_fetcher_listener: true
body_converter:
    enabled: true
sensio_framework_extra:
    view:    { annotations: false }
    router:  { annotations: true }
    request: { converters: true }
Method:
/**
 * @View()
 * @Put("/documenttypes")
 * @ParamConverter("documentType", converter="fos_rest.request_body")
 */
public function putAction(DocumentType $documentType)
{
    print_r($documentType);
    return $documentType;
}
In result I have empty model object:
Backend\SettingsBundle\Model\DocumentType Object
(
  [id:protected] => 
  [name:protected] => 
  ....
)
To check that data comes to server, I modify method:
public function putAction(DocumentType $documentType)
  {
    $content = $this->get("request")->getContent();
    $documentType->fromArray(json_decode($content, true));
    print_r($documentType);
    return $documentType;
  }
This method works and fills model field:
Backend\SettingsBundle\Model\DocumentType Object
(
  [id:protected] => 2
  [name:protected] => 'Oferta'
  ....
)
Symfony is complaining that You need to enable fos_rest.converter.request_body service. 
In your fos_rest configuration section within config.yml you need to enable body_converter feature:
fos_rest:
  body_converter:
    enabled: true
Now if you list your services, you will notice that service fos_rest.converter.request_body has appeared:
user@host:~/symfony-project$ php app/console debug:container | grep fos_rest.converter
 fos_rest.converter.request_body       FOS\RestBundle\Request\RequestBodyParamConverter        
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With