-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Open
Labels
area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesIncludes: MVC, Actions and Controllers, Localization, CORS, most templates
Milestone
Description
Is there an existing issue for this?
- I have searched the existing issuesTo pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
Describe the bug
The Read
method in the custom HoursMinutesOnlyJsonConverter
is never called during deserialization of a .net core API project. The Request
class is being used inside a few Controllers
with a [FromBody]
tag.
public class Request
{
[JsonConverter(typeof(HoursMinutesOnlyJsonConverter))]
public TimeOnly? Time { get; set; }
}
public class Response
{
[JsonConverter(typeof(HoursMinutesOnlyJsonConverter))]
public TimeOnly? Time { get; set; }
}
public class HoursMinutesOnlyJsonConverter : JsonConverter<TimeOnly?>
{
public override TimeOnly? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
// THIS IS NEVER BEING CALLED
return null;
}
public override void Write(Utf8JsonWriter writer, TimeOnly? value, JsonSerializerOptions options)
{
// THIS WORKS AS EXPECTED
if (value == null)
{
writer.WriteNullValue();
}
else
{
writer.WriteStringValue(((TimeOnly)value).ToString("hh:mm"));
}
}
}
Expected Behavior
The custom converter should be called during deserialization.
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
8.0.101
Anything else?
No response
casperOne and boukenka
Metadata
Metadata
Assignees
Labels
area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesIncludes: MVC, Actions and Controllers, Localization, CORS, most templates
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
maets commentedon Jun 17, 2025
Having the same problem. Are there any updates?
maets commentedon Jun 17, 2025
Solved my own issue by adding the following override to my custom converter:
public override bool HandleNull => true;
I guess it's optimized by circumventing the converter if encountering null or something like that