dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.4k stars 10k forks source link

`JsonPatchDocument.ApplyTo` should support `DateOnly` data type #40916

Open mcaden opened 2 years ago

mcaden commented 2 years ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe the problem.

DateTime works fine from JsonPatchDocument. However, DateOnly will not parse from a string and you can't set its year/month/day from properties so you can't build up a new object and "patch" it.

Describe the solution you'd like

DateOnly should parse via JsonPatch from an ISO8601 date string that JavaScript uses.

Alternatively, even a simple YYYY-MM-DD.

Additional context

The specific issue is that when sending a date string as an ISO 8601 value to be patched into a DateOnly object such as 2022-03-17T00:00:00.000Z the ApplyTo call fails with The value '3/17/2022 12:00:00 AM' is invalid for target location.

TanayParikh commented 2 years ago

This is likely a duplicate of https://github.com/dotnet/runtime/issues/53539.

mcaden commented 2 years ago

I don't think so... I'm using Newtonsoft and I've implemented the proper JsonConverters. Judging by https://github.com/dotnet/aspnetcore/blob/main/src/Features/JsonPatch/src/Internal/ConversionResultProvider.cs which is what tracing ApplyTo leads to it doesn't look like there's an easy way to specify the contract resolver for that specific property without messing with JsonPatch's internals.

ghost commented 2 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

maddiemccoyyy commented 9 months ago

A workaround I used is to format payload value YYYY-MM-DD rather than use ISO8601 YYYY-MM-DDT00:00:00Z

For example, PATCH [{op: "replace", path: "/example", value: "2024-01-02"}] => succeeds PATCH [{op: "replace", path: "/example", value: "2024-01-02T00:00:00"}] => fails with exception "The value '01/02/2024 00:00:00' is invalid for target location."