I am developing a simple REST API for an application using Symfony and JMS Serializer Bundle. I have a few URLs - for example /api/answers/{id}
. Now the problem is if I call that URL with id=1, everything works like a charm, when I call it with id=2, 3, 4... the JSON content is encoded improperly.
The backend script looks like this (It's just a prototype I will refactor it):
public function getByQuestionIdAction($questionId)
{
$answers = $this->getDoctrine()->getRepository('B2GameBundle:Answer')->findByQuestion($this->getDoctrine()
->getRepository('B2GameBundle:Question')->find($questionId));
$serializer = $this->get('jms_serializer');
if(!empty($answers))
{
return Response::create($serializer->serialize($answers, 'json'), 200, array("Content-type" => "application/json"));
}
else
{
return Response::create(json_encode(array('error' => 'No answers for question with id ' . $questionId . ' found!')), 404, array("Content-type" => "application/json"));
}
}
All my database tables are set to utf8_unicode_ci
, every bit in the configuration is set to utf8 as well.
PS: I printed the $answers variable with print_r and it's improperly encoded as well, so I suppose the problem lies at the doctrine side of thing. What do you think? What is really strange is the fact that it works fine for id=1. Mind you I look inside phpmyadmin and the text is just fine too.
Thank you.