Getting missmatch in datetime format using jms serializer and ISO8601
Asked Answered
N

2

8

I am getting this message:

Invalid datetime "2017-11-07T19:46:57.118Z", expected format Y-m-d\\TH:i:sP.

When using JMS Serializer and the config:

jms_serializer:
    handlers:
        datetime:
            default_format: 'Y-m-d\\TH:i:sP'

I think that my supplied date is in the correct format, but apparently not. Is it something that is wrong with the date?

Naphthalene answered 7/11, 2017 at 14:50 Comment(5)
The date doc say one slash. Have you try it? Y-m-d\TH:i:sP'Nagpur
Yes, with the same resultNaphthalene
The format problem seems to be from .118 . it seems to be microsecondNagpur
Have you tried with default_format: "c" ?Villainage
I tried c, but that did not solve it. About the microseconds, is that in the ISO8601 or not?Naphthalene
M
14

This is a tough one, I've run into it before. I was using annotations so my fix looked like:

 @Serializer\Type("DateTime<'Y-m-d\TH:i:s.uT'>")

So I'm guessing yours is going to look like:

jms_serializer:
    handlers:
        datetime:
            default_format: 'Y-m-d\TH:i:s.uT'

Or you may have to add another slash in there before "TH" if jms reads yaml files differently than annotations.

Can't remember exactly why this happens, I just remember trying a hundred different combinations until one worked. At any rate, dates and times are hard.

Mcinnis answered 7/11, 2017 at 15:27 Comment(1)
Great. Glad I could help. Yeah, this is a tough one. That error message is misleading.Mcinnis
A
0
jms_serializer:
handlers:
    datetime:
        default_format: 'Y-m-d\TH:i:s.uP'

Use 'Y-m-d\TH:i:s.uP' if you want to serialize/deserialize joda DateTime

(using joda DateTimeConverter on the client)

Amyamyas answered 5/12, 2021 at 15:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.