How to set json serializer settings in asp.net core 3?

后端 未结 3 1013
执笔经年
执笔经年 2020-12-05 22:42

json serializer settings for legacy asp.net core applications were set by adding AddMvc().AddJsonOptions(), but I don\'t use AddMvc() in asp.

3条回答
  •  时光取名叫无心
    2020-12-05 23:01

    Adding Newtonsoft is not necessary, quite a problems with adding Newtonsoft compatibility packages on .Net Core 3.0 project.

    See also https://github.com/aspnet/AspNetCore/issues/13564

    Of course, one would celebrate property naming PascalCase, NA at the moment... So null for PropertyNamingPolicy means PascalCase, which is obviously not very good.

    // Pascal casing
    services.AddControllersWithViews().
            AddJsonOptions(options =>
            {
                options.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
                options.JsonSerializerOptions.PropertyNamingPolicy = null;
            });
    

提交回复
热议问题