Default deserializeFormats for DateTime in JMS Serializer

681 Views Asked by At

I see default_format and default_timezone configs for deserializing datetime values but I don't see a config to specify a list of alternate formats. I would like for my API to accept timestamps with our without timezone (assuming UTC if not specified) and with or without fractional seconds (microseconds). The annotation example below accomplishes this but I'd rather not have to copy/paste that into the myriad of input types I use.

/**
 * @JMS\Type("DateTime<'Y-m-d\TH:i:s.uP', '+00:00', ['Y-m-d\TH:i:sP', 'Y-m-d\TH:i:s.uP', 'Y-m-d\TH:i:s', 'Y-m-d\TH:i:s.u']>"
 */
protected \DateTimeInterface $timestamp;

Does anyone have an example override to accomplish this? Maybe a feature request to add support for a new default_deserialize_format config?

1

There are 1 best solutions below

0
On

Typical... Finally break down, post a question, figure it out an hour later. A Handler with priorities set high so they override the build-in handlers was what I was looking for.