Symfony + JMS Serializer: Deserializing a DateTime value returns current time also

Viewed 382

I have the following annotation for the birthDate field:

  /**
    * @Serializer\SerializedName("birthDate")
    * @Serializer\Type("DateTimeImmutable<'Y-m-d'>")
    */
   public $birthDate;

In the request, I have

{
...
"birthDate": "1988-09-14",
...
}

After deserialization I get an object that also contains the current time 1988-09-14 14:32:25. Is it possible to change this from annotations? I wouldn't want to process the date afterward and set the time to 1988-09-14 00:00:00

1 Answers

You can use the annotation below. It is not very clear, but it works.

/**
 * @Serializer\SerializedName("birthDate")
 * @JMS\Type("DateTimeImmutable<'Y-m-d', '', '|Y-m-d'>")
 */
public $birthDate;
Related