문제

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.

도움이 되었습니까?

해결책 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.

다른 팁

Pass array instance ArrayCollection to FosVeiw.

convert your results to array like this:

$collection->toArray()
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top