DD.WellWorkover.Cloud/AsbCloudWebApi/Converters/DateOnlyJsonConverter.cs
2024-08-19 10:01:07 +05:00

21 lines
564 B
C#

using System;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace AsbCloudWebApi.Converters;
public class DateOnlyJsonConverter : JsonConverter<DateOnly>
{
public override DateOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return DateOnly.FromDateTime(reader.GetDateTime());
}
public override void Write(Utf8JsonWriter writer, DateOnly value, JsonSerializerOptions options)
{
var isoDate = value.ToString("O");
writer.WriteStringValue(isoDate);
}
}