Skip to content

[Serializer] Allow DateTimeNormalizer context to specify which types to handle #51372

Closed
@andrei-dascalu

Description

@andrei-dascalu

Description

I was recently in the need to have to customize the way dates are being deserialized when the API I was working on would receive JSON data. The requirement was to only deserialize certain formats (3 formats to be exact). As a bonus, we should directly deserialize those into Chronos instances (although plain DateTimeImmutable would also work).
To that end, we created a custom normalizer that would attempt to deserialize those 3 formats into a Chronos instance.
However, since DateTimeNormalizer would pick up said object on account that Chronos implements DateTimeInterface/DateTimeImmutable we ended up having to deregister the DateTimeNormalizer altogether.

Solutions based on framework that would have been helpful:

  • DateTimeNormalizer would be able to handle more than a single format
  • DateTimeNormalizer would allow its default classes to be configured so that we could eliminate those that we wanted to handle separately.

Example

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions