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

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

问题描述

我尝试遵循相关文档,这里:
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 中尝试获取 builder 对象时卡住了(请参阅此对象的第二个链接).该服务是一个已经构建的序列化程序.我应该在哪里实例化我自己的处理程序?

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 = JMSSerializerSerializerBuilder::create();

$builder = new JMSSerializerSerializerBuilder();
也许这会起作用,但让已经实例化的序列化程序使用我的处理程序会很好.获取控制器中的序列化服务:$serializer = $this->get('jms.serializer');

推荐答案

解决方案是使用正确的标签创建服务.

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

datetimezone_handler:
    class:     MyVendorMyBundleSerializerHandlerDateTimeZoneHandler
    tags:
        - { name: jms_serializer.subscribing_handler }

这篇关于在 symfony2 中创建 JMS Serializer 处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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