Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a JMS Serializer handler in symfony2

I tried to follow the related documentation, here:
http://jmsyst.com/libs/serializer/master/configuration
here
http://jmsyst.com/libs/serializer/master/handlers
and here
http://jmsyst.com/bundles/JMSSerializerBundle/master/cookbook/custom_handlers

I'm stuck when trying to get the builder object in symfony2 (see second link for this object). The service is a serializer which has already been build. Where should i instanciate my own handler?

Update:
I'm investigating one possible solution:
$builder = \JMS\Serializer\SerializerBuilder::create();
or
$builder = new \JMS\Serializer\SerializerBuilder();
maybe this will work but it would be nice to let the already instanciated serializer make use of my handler. To get the serializer service in the controller: $serializer = $this->get('jms.serializer');

like image 777
Flip Avatar asked Aug 14 '13 19:08

Flip


1 Answers

The solution is to create a service with the right tag.

datetimezone_handler:
    class:     MyVendor\MyBundle\Serializer\Handler\DateTimeZoneHandler
    tags:
        - { name: jms_serializer.subscribing_handler }
like image 155
Flip Avatar answered Sep 19 '22 11:09

Flip