Enhancement/1.x datetime serialization #2269
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Comparison of how NEST, which uses
IsoDateTimeConverterforDateTime, serializes DateTime and DateTimeOffset, compared to the default JSON.Net behaviour which does not useIsoDateTimeConverter.A summary of how NEST serializes, in conjunction with Json.Net's
DateTimeZoneHandlingNEST's behaviour (IsoDateTimeConverterHandlingTests)
DateTimeDateTimeZoneHandling.RoundTripKind(Default)DateTimeKindare handled differently:Unspecified:
DateTimeKind.UnspecifiedUtc:
ZUTC timezone identifierDateTimeKind.UtcLocal:
DateTimeKind.LocalDateTimeZoneHandling.UnspecifiedSerialized without any time zone id or offset.
Deserialized to datetime represented by IS08601 string with
DateTimeKind.UnspecifiedDateTimeZoneHandling.UtcDateTimeKindare handled differently:Unspecified:
ZUTC timezone identifierDateTimeKind.UtcEssentially,
DateTimeKind.Unspecifiedis serialized as though it wereDateTimeKind.Utcand deserialized as though it wereDateTimeKind.UtcUtc:
ZUTC timezone identifierDateTimeKind.UtcLocal:
DateTimeKind.Utc. Calling.ToLocalTime()on this instance would return aDateTimeinstance withDateTimeKind.Local.DateTimeZoneHandling.LocalDateTimeKindare handled differently:Unspecified:
DateTimeKind.LocalEssentially,
DateTimeKind.Unspecifiedis serialized asDateTimeKind.Unspecifiedand deserialized as though it wereDateTimeKind.LocalUtc:
ZUTC timezone identifierDateTimeKind.Local. Calling.ToUniversalTime()on this instance would return aDateTimeinstance withDateTimeKind.Utc.Local:
DateTimeKind.LocalDateTimeOffsetDateTimeOffsetalways serialize to an ISO8601 string representation that includes the offset as per theDateTimeOffsetinstance.DateTimeOffsetalways deserialize to datetime as represented by IS08601 string with anOffsetset to the offset within the ISO8601 representation.Json.NET's default behaviour (DateTimeZoneConverterHandlingTests)
DateTimeDateTimeZoneHandling.RoundTripKind(Default)DateTimeKindare handled differently:Unspecified:
DateTimeKind.UnspecifiedUtc:
ZUTC timezone identifierDateTimeKind.UtcLocal:
DateTimeKind.LocalDateTimeZoneHandling.UnspecifiedSerialized without any time zone id or offset.
Deserialized to datetime represented by IS08601 string with
DateTimeKind.UnspecifiedDateTimeZoneHandling.UtcDateTimeKindare handled differently:Unspecified:
ZUTC timezone identifierDateTimeKind.UtcEssentially,
DateTimeKind.Unspecifiedis serialized as though it wereDateTimeKind.Utcand deserialized as though it wereDateTimeKind.UtcUtc:
ZUTC timezone identifierDateTimeKind.UtcLocal:
ZUTC timezone identifierDateTimeKind.Utc. Calling.ToLocalTime()on this instance would return aDateTimeinstance withDateTimeKind.Local.DateTimeZoneHandling.LocalDateTimeKindare handled differently:Unspecified:
DateTimeKind.LocalEssentially,
DateTimeKind.Unspecifiedis serialized asDateTimeKind.Localand deserialized as though it wereDateTimeKind.LocalUtc:
DateTimeKind.Local. Calling.ToUniversalTime()on this instance would return aDateTimeinstance withDateTimeKind.Utc.Local:
DateTimeKind.LocalDateTimeOffsetDateTimeOffsetalways serialize to an ISO8601 string representation that includes the offset as per theDateTimeOffsetinstance.DateTimeOffsetalways deserialize to datetime as represented by IS08601 string with anOffsetset to the offset within the ISO8601 representation.Summary
The key difference between NEST's serialization and Json.NET's serialization is
DateTimeofDateTimeKind.Localare serialized when usingDateTimeZoneHandling.UtcDateTimeof all 3DateTimeKindare serialized when usingDateTimeZoneHandling.Local