Browse Source

Set NumberHandling of JsonSerializerOptions to JsonNumberHandling.Strict.

pull/9700/head
maliming 5 years ago
parent
commit
76317521fb
  1. 4
      build/common.ps1
  2. 4
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpJsonOptionsSetup.cs
  3. 6
      framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/ValueConverters/ExtraPropertiesValueConverter.cs
  4. 5
      framework/src/Volo.Abp.Json/Volo/Abp/Json/SystemTextJson/AbpSystemTextJsonSerializerOptionsSetup.cs

4
build/common.ps1

@ -6,12 +6,12 @@ $rootFolder = (Get-Item -Path "./" -Verbose).FullName
# List of solutions used only in development mode
$solutionPaths = @(
# "../framework",
"../framework",
"../modules/basic-theme",
"../modules/users",
"../modules/permission-management",
"../modules/setting-management",
# "../modules/feature-management",
"../modules/feature-management",
"../modules/identity",
"../modules/identityserver",
"../modules/tenant-management",

4
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpJsonOptionsSetup.cs

@ -30,6 +30,10 @@ namespace Volo.Abp.AspNetCore.Mvc.Json
options.JsonSerializerOptions.Converters.Add(new ObjectToInferredTypesConverter());
options.JsonSerializerOptions.Converters.Add(new AbpHasExtraPropertiesJsonConverterFactory());
// Remove after this PR.
// https://github.com/dotnet/runtime/pull/51739
options.JsonSerializerOptions.NumberHandling = JsonNumberHandling.Strict;
}
}
}

6
framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/ValueConverters/ExtraPropertiesValueConverter.cs

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Volo.Abp.Data;
using Volo.Abp.Json.SystemTextJson.JsonConverters;
@ -49,6 +50,11 @@ namespace Volo.Abp.EntityFrameworkCore.ValueConverters
var deserializeOptions = new JsonSerializerOptions();
deserializeOptions.Converters.Add(new ObjectToInferredTypesConverter());
// Remove after this PR.
// https://github.com/dotnet/runtime/pull/51739
deserializeOptions.NumberHandling = JsonNumberHandling.Strict;
var dictionary = JsonSerializer.Deserialize<ExtraPropertyDictionary>(extraPropertiesAsJson, deserializeOptions) ??
new ExtraPropertyDictionary();

5
framework/src/Volo.Abp.Json/Volo/Abp/Json/SystemTextJson/AbpSystemTextJsonSerializerOptionsSetup.cs

@ -1,5 +1,6 @@
using System;
using System.Text.Encodings.Web;
using System.Text.Json.Serialization;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Volo.Abp.Json.SystemTextJson.JsonConverters;
@ -28,6 +29,10 @@ namespace Volo.Abp.Json.SystemTextJson
// If the user hasn't explicitly configured the encoder, use the less strict encoder that does not encode all non-ASCII characters.
options.JsonSerializerOptions.Encoder ??= JavaScriptEncoder.UnsafeRelaxedJsonEscaping;
// Remove after this PR.
// https://github.com/dotnet/runtime/pull/51739
options.JsonSerializerOptions.NumberHandling = JsonNumberHandling.Strict;
}
}
}

Loading…
Cancel
Save