简体   繁体   English

JMS序列化程序yml日期时间格式

[英]JMS serializer yml datetime format

I have an Rest API built on Symfony 2.7 Framework with FOSRestBundle and JMSSerializerBundle . 我有一个基于Symfony 2.7 Framework构建的Rest API,带有FOSRestBundle和JMSSerializerBundle I have a look to yml reference and annotations . 我看看yml 参考注释

I have choosen to define how each entity of my model is serialized with yml . 我已经选择定义我的模型的每个实体如何用yml序列化。

I have seen that we can serialize Datetime object on a specific format : 我已经看到我们可以在特定格式上序列化Datetime对象:

@JMS\Type("DateTime<'d-m-Y'>")

But I don't know the correct syntax used with yml definition , I have tried : 我不知道yml定义使用的正确语法 ,我试过:

my_field:
  expose: true
  type: datetime
  format: 'd-m-Y'

And

my_field:
  expose: true
  type: datetime<'d-m-Y'>

I don't want to use Annotations because I have a lot of yaml files. 我不想使用Annotations因为我有很多yaml文件。

But the field is not serialized ... 该领域尚未序列化 ......

Anyone can help me ? 有人可以帮帮我吗?

I put it as an answer in case it helps more people: 我把它作为一个答案,以防它帮助更多的人:

my_field:
  expose: true
  type: DateTime<'d-m-Y'>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM