Browse Source

Remove `ObjectToInferredTypesConverter` from `SystemTextJsonOutputFormatter`.

pull/23410/head
maliming 6 months ago
parent
commit
c10f7628c4
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 18
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpMvcOptionsExtensions.cs
  2. 5
      framework/src/Volo.Abp.Json.SystemTextJson/Volo/Abp/Json/SystemTextJson/JsonConverters/ObjectToInferredTypesConverter.cs

18
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpMvcOptionsExtensions.cs

@ -1,5 +1,9 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata;
using Microsoft.Extensions.DependencyInjection;
@ -14,6 +18,7 @@ using Volo.Abp.AspNetCore.Mvc.Response;
using Volo.Abp.AspNetCore.Mvc.Uow;
using Volo.Abp.AspNetCore.Mvc.Validation;
using Volo.Abp.Content;
using Volo.Abp.Json.SystemTextJson.JsonConverters;
namespace Volo.Abp.AspNetCore.Mvc;
@ -32,6 +37,17 @@ internal static class AbpMvcOptionsExtensions
private static void AddFormatters(MvcOptions options)
{
options.OutputFormatters.Insert(0, new RemoteStreamContentOutputFormatter());
var systemTextJsonOutputFormatter = options.OutputFormatters
.Where(f => f is SystemTextJsonOutputFormatter)
.Cast<SystemTextJsonOutputFormatter>().FirstOrDefault();
if (systemTextJsonOutputFormatter != null)
{
options.OutputFormatters.Remove(systemTextJsonOutputFormatter);
var jsonOptions = new JsonSerializerOptions(systemTextJsonOutputFormatter.SerializerOptions);
jsonOptions.Converters.RemoveAll(x => x is ObjectToInferredTypesConverter);
options.OutputFormatters.Add(new SystemTextJsonOutputFormatter(jsonOptions));
}
}
private static void AddConventions(MvcOptions options, IServiceCollection services)

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

@ -9,11 +9,6 @@ namespace Volo.Abp.Json.SystemTextJson.JsonConverters;
/// </summary>
public class ObjectToInferredTypesConverter : JsonConverter<object>
{
public override bool CanConvert(Type typeToConvert)
{
return typeToConvert == typeof(object);
}
public override object Read(
ref Utf8JsonReader reader,
Type typeToConvert,

Loading…
Cancel
Save