I'm bound by agreements between my party and the client to use json parameters containing dashes. Since it's not possible to use that in property names in C#, I need to map to the desired property.
What I do now:
The below code is simplified for convenience.
Model
public class MyRequest
{
[JsonProperty("request-number")]
public string RequestNumber { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
}
Controller
[HttpGet]
[Route("api/load-stuff")]
public Stuff LoadStuff([FromUri]MyRequest request)
{
return BackEnd.LoadStuff(request);
}
Call to the API from client
The above controller is targeted using this uri:
http://localhost:12345/api/load-stuff?request-number=X123&name=requestName
My question
If I put a breakpoint at the BackEnd.LoadStuff
line I can see the call arrives, but the request isn't mapped correctly.
Name contains what I expect:
requestName
, but RequestNumber isnull
, so the mapping didn't work.
What's going wrong?