我无法使用 JIL 的 Exclude Null 选项。相反,我得到一个例外:
JIL.DeserializationException:'预期的数字'
以下是代码片段。
public Task<InputFormatterResult> ReadAsync(InputFormatterContext context)
{
if (context == null) throw new ArgumentNullException(nameof(context));
var request = context.HttpContext.Request; if (request.ContentLength == 0)
{
if (context.ModelType.GetTypeInfo().IsValueType)
return InputFormatterResult.SuccessAsync(Activator.CreateInstance(context.ModelType));
else return InputFormatterResult.SuccessAsync(null);
}
var encoding = Encoding.UTF8;//do we need to get this from the request im not sure yet
using (var reader = new StreamReader(context.HttpContext.Request.Body))
{
var model = Jil.JSON.Deserialize(reader, context.ModelType, Jil.Options.ExcludeNulls);
return InputFormatterResult.SuccessAsync(model);
}
}
1) 型号类型
public class PaymentTypeBORequest
{
public int pkId { get; set; }
public string description { get; set; }
public bool isSystem { get; set; }
public bool isActive { get; set; }
}
2)JSON字符串:
{
"pkId":null,
"description": "Adjustment",
"isSystem": true,
"isActive": true
}