Browse Source

Rename AbpSystemTextJsonSupportTypeMatcher to AbpSystemTextJsonUnsupportedTypeMatcher.

pull/5952/head
maliming 6 years ago
parent
commit
2ab31f491f
  1. 4
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonInputFormatter.cs
  2. 4
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonOutputFormatter.cs
  3. 8
      framework/src/Volo.Abp.Json/Volo/Abp/Json/SystemTextJson/AbpSystemTextJsonSerializerProvider.cs
  4. 6
      framework/src/Volo.Abp.Json/Volo/Abp/Json/SystemTextJson/AbpSystemTextJsonUnsupportedTypeMatcher.cs
  5. 66
      framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpSystemTextJsonSupportTypeMatcher_Tests.cs
  6. 66
      framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpSystemTextJsonUnsupportedTypeMatcher_Tests.cs

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

@ -25,8 +25,8 @@ namespace Volo.Abp.AspNetCore.Mvc.Json
protected virtual TextInputFormatter GetTextInputFormatter(InputFormatterContext context) protected virtual TextInputFormatter GetTextInputFormatter(InputFormatterContext context)
{ {
var typesMatcher = context.HttpContext.RequestServices.GetRequiredService<AbpSystemTextJsonSupportTypeMatcher>(); var typesMatcher = context.HttpContext.RequestServices.GetRequiredService<AbpSystemTextJsonUnsupportedTypeMatcher>();
if (typesMatcher.Match(context.ModelType)) if (!typesMatcher.Match(context.ModelType))
{ {
return context.HttpContext.RequestServices.GetRequiredService<SystemTextJsonInputFormatter>(); return context.HttpContext.RequestServices.GetRequiredService<SystemTextJsonInputFormatter>();
} }

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

@ -25,8 +25,8 @@ namespace Volo.Abp.AspNetCore.Mvc.Json
protected virtual TextOutputFormatter GetTextInputFormatter(OutputFormatterWriteContext context) protected virtual TextOutputFormatter GetTextInputFormatter(OutputFormatterWriteContext context)
{ {
var typesMatcher = context.HttpContext.RequestServices.GetRequiredService<AbpSystemTextJsonSupportTypeMatcher>(); var typesMatcher = context.HttpContext.RequestServices.GetRequiredService<AbpSystemTextJsonUnsupportedTypeMatcher>();
if (typesMatcher.Match(context.ObjectType)) if (!typesMatcher.Match(context.ObjectType))
{ {
return context.HttpContext.RequestServices.GetRequiredService<SystemTextJsonOutputFormatter>(); return context.HttpContext.RequestServices.GetRequiredService<SystemTextJsonOutputFormatter>();
} }

8
framework/src/Volo.Abp.Json/Volo/Abp/Json/SystemTextJson/AbpSystemTextJsonSerializerProvider.cs

@ -9,19 +9,19 @@ namespace Volo.Abp.Json.SystemTextJson
{ {
protected AbpSystemTextJsonSerializerOptions Options { get; } protected AbpSystemTextJsonSerializerOptions Options { get; }
protected AbpSystemTextJsonSupportTypeMatcher AbpSystemTextJsonSupportTypeMatcher { get; } protected AbpSystemTextJsonUnsupportedTypeMatcher AbpSystemTextJsonUnsupportedTypeMatcher { get; }
public AbpSystemTextJsonSerializerProvider( public AbpSystemTextJsonSerializerProvider(
IOptions<AbpSystemTextJsonSerializerOptions> options, IOptions<AbpSystemTextJsonSerializerOptions> options,
AbpSystemTextJsonSupportTypeMatcher abpSystemTextJsonSupportTypeMatcher) AbpSystemTextJsonUnsupportedTypeMatcher abpSystemTextJsonUnsupportedTypeMatcher)
{ {
AbpSystemTextJsonSupportTypeMatcher = abpSystemTextJsonSupportTypeMatcher; AbpSystemTextJsonUnsupportedTypeMatcher = abpSystemTextJsonUnsupportedTypeMatcher;
Options = options.Value; Options = options.Value;
} }
public bool CanHandle(Type type) public bool CanHandle(Type type)
{ {
return AbpSystemTextJsonSupportTypeMatcher.Match(type); return !AbpSystemTextJsonUnsupportedTypeMatcher.Match(type);
} }
public string Serialize(object obj, bool camelCase = true, bool indented = false) public string Serialize(object obj, bool camelCase = true, bool indented = false)

6
framework/src/Volo.Abp.Json/Volo/Abp/Json/SystemTextJson/AbpSystemTextJsonSupportTypeMatcher.cs → framework/src/Volo.Abp.Json/Volo/Abp/Json/SystemTextJson/AbpSystemTextJsonUnsupportedTypeMatcher.cs

@ -4,18 +4,18 @@ using Volo.Abp.DependencyInjection;
namespace Volo.Abp.Json.SystemTextJson namespace Volo.Abp.Json.SystemTextJson
{ {
public class AbpSystemTextJsonSupportTypeMatcher : ITransientDependency public class AbpSystemTextJsonUnsupportedTypeMatcher : ITransientDependency
{ {
protected AbpSystemTextJsonSerializerOptions Options { get; } protected AbpSystemTextJsonSerializerOptions Options { get; }
public AbpSystemTextJsonSupportTypeMatcher(IOptions<AbpSystemTextJsonSerializerOptions> options) public AbpSystemTextJsonUnsupportedTypeMatcher(IOptions<AbpSystemTextJsonSerializerOptions> options)
{ {
Options = options.Value; Options = options.Value;
} }
public virtual bool Match(Type type) public virtual bool Match(Type type)
{ {
return !Options.UnsupportedTypes.Contains(type); return Options.UnsupportedTypes.Contains(type);
} }
} }
} }

66
framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpSystemTextJsonSupportTypeMatcher_Tests.cs

@ -1,66 +0,0 @@
using System;
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Volo.Abp.Json.SystemTextJson;
using Xunit;
namespace Volo.Abp.Json
{
public class AbpSystemTextJsonSupportTypeMatcher_Tests : AbpJsonTestBase
{
private readonly AbpSystemTextJsonSupportTypeMatcher _abpSystemTextJsonSupportTypeMatcher;
public AbpSystemTextJsonSupportTypeMatcher_Tests()
{
_abpSystemTextJsonSupportTypeMatcher = GetRequiredService<AbpSystemTextJsonSupportTypeMatcher>();
}
protected override void AfterAddApplication(IServiceCollection services)
{
services.Configure<AbpSystemTextJsonSerializerOptions>(options =>
{
options.UnsupportedTypes.Add<MyClass>();
options.UnsupportedTypes.Add<byte[]>();
options.UnsupportedTypes.Add<Dictionary<string, MyClass4>>();
});
}
[Fact]
public void CanHandle_Test()
{
_abpSystemTextJsonSupportTypeMatcher.Match(typeof(MyClass)).ShouldBeFalse();
_abpSystemTextJsonSupportTypeMatcher.Match(typeof(byte[])).ShouldBeFalse();
_abpSystemTextJsonSupportTypeMatcher.Match(typeof(MyClass2)).ShouldBeTrue();
_abpSystemTextJsonSupportTypeMatcher.Match(typeof(MyClass3)).ShouldBeTrue();
_abpSystemTextJsonSupportTypeMatcher.Match(typeof(MyClass4)).ShouldBeTrue();
_abpSystemTextJsonSupportTypeMatcher.Match(typeof(string)).ShouldBeTrue();
_abpSystemTextJsonSupportTypeMatcher.Match(typeof(string[])).ShouldBeTrue();
_abpSystemTextJsonSupportTypeMatcher.Match(typeof(Dictionary<string, MyClass4>)).ShouldBeFalse();
_abpSystemTextJsonSupportTypeMatcher.Match(typeof(IDictionary<string, MyClass4>)).ShouldBeTrue();
}
class MyClass
{
public DateTime Prop1 { get; set; }
}
class MyClass2
{
public DateTime Prop1 { get; set; }
}
class MyClass3
{
public MyClass4 Prop1 { get; set; }
}
class MyClass4
{
public DateTime Prop1 { get; set; }
}
}
}

66
framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpSystemTextJsonUnsupportedTypeMatcher_Tests.cs

@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Volo.Abp.Json.SystemTextJson;
using Xunit;
namespace Volo.Abp.Json
{
public class AbpSystemTextJsonUnsupportedTypeMatcher_Tests : AbpJsonTestBase
{
private readonly AbpSystemTextJsonUnsupportedTypeMatcher _abpSystemTextJsonUnsupportedTypeMatcher;
public AbpSystemTextJsonUnsupportedTypeMatcher_Tests()
{
_abpSystemTextJsonUnsupportedTypeMatcher = GetRequiredService<AbpSystemTextJsonUnsupportedTypeMatcher>();
}
protected override void AfterAddApplication(IServiceCollection services)
{
services.Configure<AbpSystemTextJsonSerializerOptions>(options =>
{
options.UnsupportedTypes.Add<MyClass>();
options.UnsupportedTypes.Add<byte[]>();
options.UnsupportedTypes.Add<Dictionary<string, MyClass4>>();
});
}
[Fact]
public void Match_Test()
{
_abpSystemTextJsonUnsupportedTypeMatcher.Match(typeof(MyClass)).ShouldBeTrue();
_abpSystemTextJsonUnsupportedTypeMatcher.Match(typeof(byte[])).ShouldBeTrue();
_abpSystemTextJsonUnsupportedTypeMatcher.Match(typeof(MyClass2)).ShouldBeFalse();
_abpSystemTextJsonUnsupportedTypeMatcher.Match(typeof(MyClass3)).ShouldBeFalse();
_abpSystemTextJsonUnsupportedTypeMatcher.Match(typeof(MyClass4)).ShouldBeFalse();
_abpSystemTextJsonUnsupportedTypeMatcher.Match(typeof(string)).ShouldBeFalse();
_abpSystemTextJsonUnsupportedTypeMatcher.Match(typeof(string[])).ShouldBeFalse();
_abpSystemTextJsonUnsupportedTypeMatcher.Match(typeof(Dictionary<string, MyClass4>)).ShouldBeTrue();
_abpSystemTextJsonUnsupportedTypeMatcher.Match(typeof(IDictionary<string, MyClass4>)).ShouldBeFalse();
}
class MyClass
{
public DateTime Prop1 { get; set; }
}
class MyClass2
{
public DateTime Prop1 { get; set; }
}
class MyClass3
{
public MyClass4 Prop1 { get; set; }
}
class MyClass4
{
public DateTime Prop1 { get; set; }
}
}
}
Loading…
Cancel
Save