.net core 3.0 still cannot handle TimeSpans. So I created my own TimeSpanConverter:
public class TimeSpanConverter : JsonConverter<TimeSpan> {
public override TimeSpan Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) {
return TimeSpan.Parse(reader.GetString());
}
public override void Write(Utf8JsonWriter writer, TimeSpan value, JsonSerializerOptions options) {
writer.WriteStringValue(value.ToString(@"hh\:mm"));
}
}
Now all it needs is registering in the startup.cs:
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews().AddJsonOptions(options => {
options.JsonSerializerOptions.Converters.Add(new TimeSpanConverter());
});
}
Done!