In my Razor Pages project, I have created this custom JsonConverter
public class MyConverter : JsonConverter<Instant>
{
public override Instant Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
// implementation
}
public override void Write(Utf8JsonWriter writer, Instant value, JsonSerializerOptions options)
{
// implementation
}
}
I applied it to two properties of this object
public class Event
{
[JsonConverter(typeof(MyConverter))]
public Instant Start { get; set; }
[JsonConverter(typeof(MyConverter))]
public Instant End { get; set; }
// Other properties
}
OnGet works fine, the model is well serialized.
The problem is when I post this model on the function below, my custom converter is not called at all.
public async Task<IActionResult> OnPost(Event evt)
Here is the form data sent with fetch.
start=2022-03-18&end=2022-03-18
If Start
and End
properties would be string it maps well.
I don't have any error, nothing. Any idea on what am I doing wrong ?