C
C#7mo ago
PIE

Can't figure out how to apply attributes to values in json property dictionary (System.Text.Json)

This is my model that I'm working with
//TODO convert to DateTime
[JsonPropertyName("peace")]
[JsonConverter(typeof(UnixDateTimeConverter))]
public Dictionary<int, DateTime> Peace { get; set; }
//TODO convert to DateTime
[JsonPropertyName("peace")]
[JsonConverter(typeof(UnixDateTimeConverter))]
public Dictionary<int, DateTime> Peace { get; set; }
The converter I'm using can convert integers to date time like so:
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return DateTime.UnixEpoch.AddMilliseconds(reader.GetInt64());
}
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return DateTime.UnixEpoch.AddMilliseconds(reader.GetInt64());
}
is there a way to change the converter to support dictionarys/lists? or apply the attribute to all values in a dictionarys/list?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server