JMS serializer yml datetime format
Asked Answered
L

1

7

I have an Rest API built on Symfony 2.7 Framework with FOSRestBundle and JMSSerializerBundle. I have a look to yml reference and annotations.

I have choosen to define how each entity of my model is serialized with yml.

I have seen that we can serialize Datetime object on a specific format :

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

But I don't know the correct syntax used with yml definition, I have tried :

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.

But the field is not serialized...

Anyone can help me ?

Luigi answered 10/1, 2017 at 13:12 Comment(2)
did you try?: type: "DateTime<'d-m-Y'>" or type: "DateTime('d-m-Y')"Dollhouse
The correct answer is DateTime<'d-m-Y'>, thanks for the help !Luigi
D
14

I put it as an answer in case it helps more people:

my_field:
  expose: true
  type: DateTime<'d-m-Y'>
Dollhouse answered 10/1, 2017 at 15:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.