Reputation: 3689
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.
Upvotes: 1
Views: 434
Reputation: 3689
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.
Upvotes: 0
Reputation: 1306
Pass array
instance ArrayCollection
to FosVeiw
.
convert your results to array like this:
$collection->toArray()
Upvotes: 1