问题描述
我尝试在此处关注相关文档:
在这里
和此处
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
尝试在symfony2中获取构建器对象时遇到问题(请参阅此对象的第二个链接)。该服务是已构建的序列化程序。我应该在哪里实例化自己的处理程序?
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?
更新:
我正在研究一种可能的解决方案:
$ builder = \JMS\Serializer\SerializerBuilder :: create();
或
$ builder = new \JMS\Serializer\SerializerBuilder();
也许可以使用,但是让已经实例化的序列化程序使用我的处理程序会很好。要在控制器中获取序列化程序服务: $ serializer = $ this-> get('jms.serializer');
推荐答案
解决方案是创建带有正确标签的服务。
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 }
这篇关于在symfony2中创建JMS序列化程序处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!