8

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');

1 Answer 1

15

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 }
2
  • you save my day twice in this month. I used to serialize FosUser entity, for entity "type" need by "My\\UserBundle\\Entity\\User" Feb 14, 2015 at 12:03
  • 2
    This doesn't work for me. I have it set up like this and it still doesn't register the handler. It never gets into getSubscribingMethods() on the handler.
    – Nicolas
    Aug 2, 2016 at 13:06

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.