Response from FOSRestController fail due to default underscore naming
SDPrio opened this issue · 3 comments
Hi,
I am using a FOSRestController
to return the result of the RequestHandler
to Amazon as JSON. The problem is, that the underlying JMSSerializer
uses underscore naming while the Amazon API expects camel case:
class AlexaController extends AbstractFOSRestController {
public function alexaAction(Request $request) {
...
$responseData = $transformer->transformRequest(
$request,
$request->headers->get('SIGNATURECERTCHAINURL'),
$request->headers->get('SIGNATURE')
);
// The registered handler returns a simple text/speech response
// return $this->responseHelper->respond('Hello World!');
$view = $this->view($responseData, 200);
return $this->handleView($view);
}
}
// Response:
{
"version" : "1.0",
"session_attributes" : [],
"response" : {
"output_speech": ... <= Amazon expects "outputSpeech" instead
}
}
I know that I could change the naming strategy used by JMSSerializer
in the projects parameters.yml
file. However, this would change the behavior globally all over the project and thus affect existing APIs.
Is there any way to define which naming strategy (camel case) has to be used when serializing the response data?
Hi,
thanks for your comment. There is already a issue (see #13) to make this lib jmsserializer ready. But at the Moment there is no way by this library. I have to find some time for that. I guess it will take some time.
Thanks! So not using FOSRest
but toJSON
instead is the correct solution?
For the moment yes you should create the json without jms. Or you still use the bundle i created for the moment.