"Null" string passed to controllers, despite option for custom null value
See original GitHub issueThe Null value used for query parameters which are null
option does not work for a parameter of type string
.
I created a GET method with this signature, so I have a string
, a DateTime?
and a DateTime
:
public async Task<ActionResult<bool>> HasOauthMapping(string accessToken, DateTime nonNullableDate, DateTime? nullableDate)
The generated typescript (Angular) code is as follows (with "foo"
used for the ‘substitute’ null value):
if (accessToken !== undefined)
url_ += "accessToken=" + encodeURIComponent("" + accessToken) + "&";
if (nonNullableDate === null)
throw new Error("The parameter 'nonNullableDate' cannot be null.");
else if (nonNullableDate !== undefined)
url_ += "nonNullableDate=" + encodeURIComponent(nonNullableDate ? "" + xnonNullableDate.toJSON() : "foo") + "&";
if (nullableDate !== undefined)
url_ += "nullableDate=" + encodeURIComponent(nullableDate ? "" + nullableDate.toJSON() : "foo") + "&";
url_ = url_.replace(/[?&]$/, "");
As you can see the value "foo"
is correctly substituted for both DateTime
parameters but for a string
parameter a null value gets converted to "" + null
or the actual string "null"
.
I can pass undefined
but I’d much prefer for the same logic to apply for all data types.
This is similar to this issue https://github.com/RSuter/NSwag/issues/1168
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Controller is populating objects with null value despite ...
Controller is populating objects with null value despite them not being bound · The correct approach is to get the data model based...
Read more >Apex Component Controller returning Null for simple string ...
VF Page (no controller). I want to pass a string value from the page to the component. <apex:page lightningStylesheets= ...
Read more >Use empty string, null or remove empty property in API ...
Json translates null/missing properties to/from F# option types only and will otherwise ... Empty string still is a value, it is just empty....
Read more >Understanding null safety
Since Null is no longer a subtype, no type except the special Null class permits the value null . We've made all types...
Read more >C# 11.0 preview: parameter null checking
C# 11.0 has a new syntax, !!, which makes it easier to detect and reject null arguments. It is simple, but misunderstood.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I would find it very useful if you could customise the “null string” that the
Null value used for query parameters which are null
promises to do, rather than have it hard-coded to""
. In many situations the empty string is a perfectly valid input which is not semantically the same asnull
, and you need to be able to distinguish between the two. Or you may simply be attempting to connect with a service beyond your control which uses a different convention for representing nulls than this.Common options include:
/endpoint?foo=%00&bar=1
);/endpoint?foo&bar=1
- no equals sign)""
as you say (/endpoint?foo=&bar=1
);/endpoint?foo=#NULL#&bar=1
if#
is an illegal character, say)APIs vary so support for any of these cases, not just the
""
case, would be tremendous.I think we should send “” instead of “null” when passing a null parameter, right? “null” does not make sense in any case…