Web API does not differentiate between [1, 2] and ["1", "2"]

118 Views Asked by At

I have created a Web API endpoint for PUT request and I expect the request body to be string array like ["1", "2"]. But when I pass [1, 2] it does not show error and calls the API with below method signature.

public HttpResponseMessage UpdateFeatures(
    [FromUri()] int parentId, 
    [FromUri()] int classId, 
    [FromBody] List<string> featureIdList)

How can I stop this implicit conversion from int array to string array? My request content-type is application/json

For now I have created ValidateStringArrayAttribute action filter to solve the problem using JSON Schema validation. But I believe there must be a better way to stop this implicit conversion from int array to string array.

0

There are 0 best solutions below