内容目录
从 ServerlessWorkflow 中学习到一个有趣的 NewtonsoftJson 配置。
var newtonsoftJsonDefaultConfig = (JsonSerializerSettings settings) =>
{
settings.ContractResolver = new NonPublicSetterContractResolver();
settings.NullValueHandling = NullValueHandling.Ignore;
settings.DefaultValueHandling = DefaultValueHandling.Ignore;
};
var defaultSettings = JsonConvert.DefaultSettings;
JsonConvert.DefaultSettings = () =>
{
var settings = defaultSettings?.Invoke();
if (settings == null)
settings = new();
newtonsoftJsonDefaultConfig(settings);
return settings;
};
services.AddNewtonsoftJsonSerializer(options =>
{
newtonsoftJsonDefaultConfig(options);
});
文章评论