Skip to content

Regression in 1.22.1: loss of ability to customize DateTimeOffset parsing #692

@ajtribick

Description

@ajtribick

Since 1.22.1, the ability to customize the parsing of DateTimeOffset by adding a JsonConverter<DateTimeOffset> to the context has been lost. The use case I had for doing this was to customize the handling of values without a timezone to default to UTC rather than local timezone.

The problem appears to have been introduced in #670 - the previous handling would try to deserialize via TryGetUsingTypeInfo, then fall back to DateTimeOffset.Parse. The new handling first tries JsonElement.TryGetDateTimeOffset (which does not use the converters in the options) then falls back to TryGetUsingTypeInfo. Since a value without a timezone specifier does get handled by JsonElement.TryGetDateTimeOffset, the JsonConverter<DateTimeOffset> never gets invoked, and I end up with values in the wrong timezone.

Please either restore the previous behaviour where the conversion that takes account of JsonConverter<DateTimeOffset> is tried first, or provide another way to customize the parsing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Needs Triage 🔍

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions