Skip to content

DateTimeOffset is modified during deserialization #509

Closed
@milosloub

Description

@milosloub

Description

The problem is on this line

var bodyJToken = JToken.Parse(requestBody);

When using DateTimeOffset type and using JToken.Parse, it is converted to DateTime (so it is modified) as it is hardcoded as a standard behavior, see:
JamesNK/Newtonsoft.Json#862
(it is closed, but still unresolved for JToken.Parse)

Solution is change JToken.Parse to JToken.Load with StringReader and set option DateParseHandling = DateParseHandling.None; (default is DateTime). It is described here:
JamesNK/Newtonsoft.Json#862 (comment)

This issue solved global datetimeoffset destroying data, beacuse there is no option to pass another settings to JToken.Parser to override this default.

Environment

  • JsonApiDotNetCore Version 3.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions