Reputation:
I'd like to make R a nullable int (and b a nullable bool). I can hit /api/test/1/2
no problem but /api/test/null/2
causes SerializationException
KeyValueDataContractDeserializer: Error converting to type: Input string was not in a correct format
I tried doing /api/test//2
but it ignored the double slash and thought it was {Ids}.
How do I make R nullable?
[Route("/Test")]
[Route("/Test/{Ids}")]
[Route("/Test/{R}/{E}")]
[Route("/Test/a/{Ids}/{R}/{E}/{b}/{f}")]
public class Test
{
public long[] Ids { get; set; }
public int? R{get;set;}
public int E{get;set;}
public bool? b { get; set; }
public float f { get; set; }
}
public class TestService : Service
{
public object Get(Test a)
{
return JsonSerializer.SerializeToString(a);
}
}
Upvotes: 2
Views: 296
Reputation: 143399
The null
in your route is treated like a string literal which obviously is not a valid number. Basically you want to avoid passing in null in the first place (i.e. avoid specifying it), e.g instead of:
/api/test/null/2
You can do:
/api/test?E=2
Upvotes: 3