Skip to content

Setting JsonSerializerSettings.DateFormatString in ShallowCopy "overrides" JsonSerializerSettings.DateFormatHandling #29532

Open
@asgerhallas

Description

@asgerhallas

The setter of JsonSerializerSettings.DateFormatString has a hidden side effect: It sets a field telling the writer (through the serializer) whether the property has been set - even if setting the property to null:

https://github.com/JamesNK/Newtonsoft.Json/blob/666d9760719e5ec5b2a50046f7dbd6a1267c01c6/Src/Newtonsoft.Json/JsonSerializerSettings.cs#L321

So when using AddNewtonsoftJson and setting DateFormatHandling = DateFormatHandling.MicrosoftDateFormat it will not be used by the serializer, because ShallowCopy sets DateFormatString (which takes precedence over DateFormatHandling) and thus triggers the above behavior:

DateFormatString = settings.DateFormatString,

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcbugThis issue describes a behavior which is not expected - a bug.good first issueGood for newcomers.help candidateIndicates that the issues may be a good fit for community to help with. Requires work from eng. team

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions