Я использую класс ApiController
ASP.NET для создания веб-API. Я обнаружил, что если я передам недопустимый JSON, вместо того, чтобы вызывающий абонент получил 500, входной параметр будет нулевым. Как в случае, если я пройду
{ "InputProperty:" "Some Value" }
что явно недопустимо для этого метода:
[HttpPost]
public Dto.OperationOutput Operation(Dto.OperationInput p_input)
{
return this.BusinessLogic.Operation(p_input);
}
Я понимаю, что p_input
это null
. Я бы предпочел отправить что-нибудь обратно, сообщив пользователю, что они не отправили действительный JSON на POST.
В моем WebApiConfig.cs
есть:
config.Formatters.JsonFormatter.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
config.Formatters.XmlFormatter.UseXmlSerializer = true;
Любые идеи? Я видел этот пример, но я считаю, что это ASP.NET MVC, а не ApiController.