php - Setting serialization groups for entity in other bundle with FOSRestBundle / JMSSerializerBundle -
i have simple rest api created using fosrestbundle, , returns serialized objects using jmsserializerbundle.
one of entities of bundle uses entity located in bundle.
i set serialization groups entity, not set aggregated entity json result empty.
i've followed documentation yaml groups configuration: http://jmsyst.com/libs/serializer/master/reference/yml_reference file seems unused (adding groups entity's properties has no effect, , don't errors if yaml file invalid).
here's code:
mycompany\mybundle\entity\meeting.php
class meeting { /** * @var point * * @orm\column(name="location", type="point", nullable=true) * @jms\groups({"privatecontact"}) */ private $location; // getters, setters , other stuff }
acme\somebundle\orm\point.php
class point { /** * @var float */ private $latitude; /** * @var float */ private $longitude; // getters, setters }
mycompany\mybundle\resources\config\serializer\model.point.yml
acme\somebundle\orm\point: properties: latitude: groups: ['privatecontact'] longitude: groups: ['privatecontact']
mycompany\mybundle\controller\apicontroller.php
/** * @rest\view(serializergroups={"privatecontact"}) */ public function getmeetingaction() { ... return array( 'status' => 'ok', 'meeting' => $meeting ); }
resulting json
"meeting":{"id":10,"date":"2015-07-16t19:20:00+0200","location":{}}
for else has encountered problem, found view annotation in example did not work. however, if set serialization context correct group in controller action worked fine:
$view->setserializationcontext(serializationcontext::create()->setgroups('site'));
Comments
Post a Comment