Fosrestbundle: How to serialize an instance of stdClass to Json ?

Created on 15 Apr 2015  路  3Comments  路  Source: FriendsOfSymfony/FOSRestBundle

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.

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);

All 3 comments

this is an issue with JMS serializer. one option would be to cast it to an array.

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);

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MaxBoltik picture MaxBoltik  路  4Comments

MaksSlesarenko picture MaksSlesarenko  路  4Comments

JeroenDeDauw picture JeroenDeDauw  路  6Comments

matrix818181 picture matrix818181  路  7Comments

dkorsak picture dkorsak  路  5Comments