18 lines
565 B
C#
18 lines
565 B
C#
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace NejCommon.Utils
|
|
{
|
|
public class DateOnlyConverter : JsonConverter<DateOnly>
|
|
{
|
|
public override DateOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
{
|
|
return DateOnly.Parse(reader.GetString() ?? string.Empty);
|
|
}
|
|
|
|
public override void Write(Utf8JsonWriter writer, DateOnly value, JsonSerializerOptions options)
|
|
{
|
|
writer.WriteStringValue(value.ToString("yyyy-MM-dd"));
|
|
}
|
|
}
|
|
} |