Posting models with NodaTime auto-props to WebAPI

ぃ、小莉子 提交于 2019-12-01 18:55:58
Matt Johnson-Pint

It appears to be a WebAPI issue, but I don't fully understand the root cause, nor do I particularly like this solution. However, based on the code in this answer, I came up with a workaround:

public class CustomBodyModelValidator : DefaultBodyModelValidator
{
    public override bool ShouldValidateType(Type type)
    {
        return type.Namespace != "NodaTime" && base.ShouldValidateType(type);
    }
}

In your configuration lambda (or wherever you are accessing the global WebAPI configuration:

x.Services.Replace(typeof(IBodyModelValidator), new CustomBodyModelValidator());

Consider this a hack of a workaround until I (or someone else) can figure out a better solution. Thanks.

Update: On further research, it appears this has already been posted to the Noda Time issue tracker as issue #249, and a similar solution was proposed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!