在symfony2中创建JMS序列化程序处理程序 [英] Creating a JMS Serializer handler in symfony2

查看:64
本文介绍了在symfony2中创建JMS序列化程序处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在此处关注相关文档:

http:/ /jmsyst.com/libs/serializer/master/configuration

在这里

http://jmsyst.com/libs/serializer/master/handlers

和此处

http://jmsyst.com/bundles/JMSSerializerBundle/master/cookbook/custom_handlers

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序列化程序处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆