Action method parameter with TypeConverter defaults to null when request does not provide query parameter

I have a class with a TypeConverter that I use as the type of an action method parameter in my web api and I would like to have it behave similarly to other parameters of complex type, meaning that it should not be null even when the request omits the parameter.


public ActionResult<RouteListsResponse> Get(
    [FromQuery] Whatever whatever,
    [FromQuery] Something something) { ... }

If I send a request where the query parameters are provided, then they get properly bound to the properties of something or in case of whatever the TypeConverter is invoked.

However if I send a request where the query parameters are not provided, then something is not null (Something has default constructor) but for whatever the TypeConverter is not invoked and the value of whatever is null (Whatever also has a default constructor).

I do understand that the TypeConverter is not invoked since there is nothing to convert. But why won't a Whatever get created with the default constructor just like in case of Something?

Should I use a custom ModelBinder instead of a TypeConverter? (Whatever is parsed from a string.)

What I would like to achieve is for whatever to behave the same way as something meaning that there should be an instance even if query parameter is not provided.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum