Hello,
I would like to serialize an instance of stdClass with setData($instance_of_stdclass).
But I get an empty json string in my request response.
Controller:
/**
* @Rest\View
* @return View
*/
public function getAction(Request $request, $id)
{
$view = View::create();
[...]
$view->setStatusCode(Response::HTTP_OK);
$view->setData($instance_of_stdclass);
return $this->handleView($view);
}
Would be nice to get a hint how to solve this. Thanks in advance.
this is an issue with JMS serializer. one option would be to cast it to an array.
this might help https://github.com/schmittjoh/serializer/pull/429
Thank you for the hint. I will try it soon with the stdClass handler.
For the moment a hack helped me:
$data = json_decode(json_encode($instance_of_stdclass), true);
Most helpful comment
Thank you for the hint. I will try it soon with the stdClass handler.
For the moment a hack helped me:
$data = json_decode(json_encode($instance_of_stdclass), true);