Browse Source

Use the extension method of SystemTextJson.

pull/10746/head
maliming 5 years ago
parent
commit
be79ff9464
No known key found for this signature in database GPG Key ID: 96224957E51C89E
  1. 5
      framework/src/Volo.Abp.Json/Volo/Abp/Json/SystemTextJson/JsonConverters/AbpHasExtraPropertiesJsonConverter.cs
  2. 4
      framework/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/JsonConverters/EntityJsonConverter.cs
  3. 2
      modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/JsonConverters/SelectionStringValueItemSourceJsonConverter.cs
  4. 6
      modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/JsonConverters/StringValueTypeJsonConverter.cs
  5. 2
      modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/JsonConverters/ValueValidatorJsonConverter.cs

5
framework/src/Volo.Abp.Json/Volo/Abp/Json/SystemTextJson/JsonConverters/AbpHasExtraPropertiesJsonConverter.cs

@ -27,12 +27,13 @@ namespace Volo.Abp.Json.SystemTextJson.JsonConverters
var rootElement = JsonDocument.ParseValue(ref reader).RootElement; var rootElement = JsonDocument.ParseValue(ref reader).RootElement;
if (rootElement.ValueKind == JsonValueKind.Object) if (rootElement.ValueKind == JsonValueKind.Object)
{ {
var extensibleObject = JsonSerializer.Deserialize<T>(rootElement.GetRawText(), newOptions); var extensibleObject = rootElement.Deserialize<T>(newOptions);
var extraPropertiesJsonProperty = rootElement.EnumerateObject().FirstOrDefault(x => x.Name.Equals(nameof(IHasExtraProperties.ExtraProperties), StringComparison.OrdinalIgnoreCase)); var extraPropertiesJsonProperty = rootElement.EnumerateObject().FirstOrDefault(x => x.Name.Equals(nameof(IHasExtraProperties.ExtraProperties), StringComparison.OrdinalIgnoreCase));
if (extraPropertiesJsonProperty.Value.ValueKind == JsonValueKind.Object) if (extraPropertiesJsonProperty.Value.ValueKind == JsonValueKind.Object)
{ {
var extraPropertyDictionary = JsonSerializer.Deserialize(extraPropertiesJsonProperty.Value.GetRawText(), typeof(ExtraPropertyDictionary), newOptions); var extraPropertyDictionary = extraPropertiesJsonProperty.Value.Deserialize(typeof(ExtraPropertyDictionary), newOptions);
ObjectHelper.TrySetProperty(extensibleObject, x => x.ExtraProperties, () => extraPropertyDictionary); ObjectHelper.TrySetProperty(extensibleObject, x => x.ExtraProperties, () => extraPropertyDictionary);
} }

4
framework/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/JsonConverters/EntityJsonConverter.cs

@ -13,12 +13,12 @@ namespace Volo.Abp.MemoryDb.JsonConverters
var jsonDocument = JsonDocument.ParseValue(ref reader); var jsonDocument = JsonDocument.ParseValue(ref reader);
if (jsonDocument.RootElement.ValueKind == JsonValueKind.Object) if (jsonDocument.RootElement.ValueKind == JsonValueKind.Object)
{ {
var entity = (TEntity)JsonSerializer.Deserialize(jsonDocument.RootElement.GetRawText(), typeToConvert); var entity = (TEntity)jsonDocument.RootElement.Deserialize(typeToConvert);
var idJsonElement = jsonDocument.RootElement.GetProperty(nameof(Entity<object>.Id)); var idJsonElement = jsonDocument.RootElement.GetProperty(nameof(Entity<object>.Id));
if (idJsonElement.ValueKind != JsonValueKind.Undefined) if (idJsonElement.ValueKind != JsonValueKind.Undefined)
{ {
var id = JsonSerializer.Deserialize<TKey>(idJsonElement.GetRawText()); var id = idJsonElement.Deserialize<TKey>();
if (id != null) if (id != null)
{ {
EntityHelper.TrySetId(entity, () => id); EntityHelper.TrySetId(entity, () => id);

2
modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/JsonConverters/SelectionStringValueItemSourceJsonConverter.cs

@ -19,7 +19,7 @@ namespace Volo.Abp.FeatureManagement.JsonConverters
var newOptions = JsonSerializerOptionsHelper.Create(options, this); var newOptions = JsonSerializerOptionsHelper.Create(options, this);
var selectionStringValueItem = var selectionStringValueItem =
JsonSerializer.Deserialize<LocalizableSelectionStringValueItem[]>(itemsJsonProperty.Value.GetRawText(), newOptions) ?? itemsJsonProperty.Value.Deserialize<LocalizableSelectionStringValueItem[]>(newOptions) ??
Array.Empty<LocalizableSelectionStringValueItem>(); Array.Empty<LocalizableSelectionStringValueItem>();
return new StaticSelectionStringValueItemSource(selectionStringValueItem.As<ISelectionStringValueItem[]>()); return new StaticSelectionStringValueItemSource(selectionStringValueItem.As<ISelectionStringValueItem[]>());

6
modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/JsonConverters/StringValueTypeJsonConverter.cs

@ -22,9 +22,9 @@ namespace Volo.Abp.FeatureManagement.JsonConverters
return name switch return name switch
{ {
"SelectionStringValueType" => JsonSerializer.Deserialize<SelectionStringValueType>(rootElement.GetRawText(), newOptions), "SelectionStringValueType" => rootElement.Deserialize<SelectionStringValueType>(newOptions),
"FreeTextStringValueType" => JsonSerializer.Deserialize<FreeTextStringValueType>(rootElement.GetRawText(), newOptions), "FreeTextStringValueType" => rootElement.Deserialize<FreeTextStringValueType>(newOptions),
"ToggleStringValueType" => JsonSerializer.Deserialize<ToggleStringValueType>(rootElement.GetRawText(), newOptions), "ToggleStringValueType" => rootElement.Deserialize<ToggleStringValueType>(newOptions),
_ => throw new ArgumentException($"{nameof(IStringValueType)} named {name} was not found!") _ => throw new ArgumentException($"{nameof(IStringValueType)} named {name} was not found!")
}; };
} }

2
modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/JsonConverters/ValueValidatorJsonConverter.cs

@ -23,7 +23,7 @@ namespace Volo.Abp.FeatureManagement.JsonConverters
if (propertiesJsonProperty.Value.ValueKind == JsonValueKind.Object) if (propertiesJsonProperty.Value.ValueKind == JsonValueKind.Object)
{ {
var newOptions = JsonSerializerOptionsHelper.Create(options, this, new ObjectToInferredTypesConverter()); var newOptions = JsonSerializerOptionsHelper.Create(options, this, new ObjectToInferredTypesConverter());
var properties = JsonSerializer.Deserialize<IDictionary<string, object>>(propertiesJsonProperty.Value.GetRawText(), newOptions); var properties = propertiesJsonProperty.Value.Deserialize<IDictionary<string, object>>(newOptions);
if (properties != null && properties.Any()) if (properties != null && properties.Any())
{ {
foreach (var property in properties) foreach (var property in properties)

Loading…
Cancel
Save