You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Related to this #6643 issue, the same is if you have DateOnly property in BackEnd and you want to send Date from FrontEnd.
You need to add also DateOnlyJsonConverter like this:
public class DateOnlyJsonConverter : JsonConverter<DateOnly>
{
public override void WriteJson
(JsonWriter writer, DateOnly value, JsonSerializer serializer)
{
writer.WriteValue(value.ToString("O"));
}
public override DateOnly ReadJson
(JsonReader reader, Type objectType, DateOnly existingValue,
bool hasExistingValue, JsonSerializer serializer)
{
var v = reader.Value;
if (v == null)
{
return DateOnly.MinValue;
}
var vType = v.GetType();
if (vType == typeof(DateTimeOffset)) //when the object is from a property
//in POST body. When used in service,
//better to have
//options.SerializerSettings.DateParseHandling =
//Newtonsoft.Json.DateParseHandling.DateTimeOffset;
{
return DateOnly.FromDateTime(((DateTimeOffset)v).DateTime);
}
if (vType == typeof(string))
{
return DateOnly.Parse((string)v); //DateOnly can parse 00001-01-01
}
if (vType == typeof(DateTime)) //when the object is from a property
//in POST body from a TS client
{
return DateOnly.FromDateTime((DateTime)v);
}
throw new NotSupportedException
($"Not yet support {vType} in {this.GetType()}.");
}
}
The text was updated successfully, but these errors were encountered:
Hi @ismcagdas,
I have create PR white this feature,
I name this converter DateOnlyJsonConverter because I also use DateOnly EntityFramework ValueConverter to map and store DateOnly properties to database column and I name this convertor: DateOnlyConverter.
Check if is ok my PR.
Nice job with aspboilerplate and abp projects 👍
Thanks
Related to this #6643 issue, the same is if you have DateOnly property in BackEnd and you want to send Date from FrontEnd.
You need to add also
DateOnlyJsonConverter
like this:The text was updated successfully, but these errors were encountered: