Skip to content

Commit

Permalink
Try to avoid issue when StringField reads value via Newtonsoft.Json a…
Browse files Browse the repository at this point in the history
…nd a DateTime token is received
  • Loading branch information
volkanceylan committed Dec 18, 2024
1 parent ca26c91 commit 87b4ba9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Serenity.Net.Services/Entity/FieldTypes/StringField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ public override void ValueFromJson(Newtonsoft.Json.JsonReader reader, IRow row,
case Newtonsoft.Json.JsonToken.Boolean:
_setValue(row, Convert.ToString(reader.Value, CultureInfo.InvariantCulture));
break;
case Newtonsoft.Json.JsonToken.Date:
var val = reader.Value is DateTimeOffset dto ? dto.DateTime : (DateTime)reader.Value!;

var style = serializer.DateFormatString ?? "o";

if (val.TimeOfDay == TimeSpan.Zero)
style = style.Contains('T') ? style.Split('T')[0] : "yyyy-MM-dd";

if (style.Contains('\''))
style = style.Replace("'", "");

_setValue(row, val.ToString(style, CultureInfo.InvariantCulture));

default:
throw JsonUnexpectedToken(reader);
}
Expand Down

0 comments on commit 87b4ba9

Please sign in to comment.