Question

I'm using FOSRestBundle and JMSSerializationBundle. When I get a Collection I get something like this:

{ "entities": [
    {
        "id": 1,
        "mainDiagnosticName": "diagnostic",
        "mainDiagnosticCode": "code",
        "startDate": "2011-01-04T21:30:40+0000",
        "endDate": null,
        "patient": null
     }]
 }

I don't want the entities stuff. I just want:

 [
    {
        "id": 1,
        "mainDiagnosticName": "diagnostic",
        "mainDiagnosticCode": "code",
        "startDate": "2011-01-04T21:30:40+0000",
        "endDate": null,
        "patient": null
     }]

How this can be done?

Many Thanks.

Was it helpful?

Solution 2

OK, I've found out:

This is because I was using the annotation FOS\RestBundle\Controller\Annotations\View, I've changed by returning my own view:

return $this->view($entities,Codes::HTTP_OK);

With an array, as hd.deman said.

And it works the way I want.

OTHER TIPS

Pass array instance ArrayCollection to FosVeiw.

convert your results to array like this:

$collection->toArray()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top