mirror of https://github.com/abpframework/abp.git
15 changed files with 243 additions and 39 deletions
@ -0,0 +1,40 @@ |
|||||
|
using System; |
||||
|
using System.Reflection; |
||||
|
using System.Text.Json; |
||||
|
using System.Text.Json.Serialization; |
||||
|
|
||||
|
namespace Volo.Abp.Json.SystemTextJson.JsonConverters |
||||
|
{ |
||||
|
public class AbpStringToEnumFactory : JsonConverterFactory |
||||
|
{ |
||||
|
private readonly JsonNamingPolicy _namingPolicy; |
||||
|
private readonly bool _allowIntegerValues; |
||||
|
|
||||
|
public AbpStringToEnumFactory() |
||||
|
: this(namingPolicy: null, allowIntegerValues: true) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public AbpStringToEnumFactory(JsonNamingPolicy namingPolicy, bool allowIntegerValues) |
||||
|
{ |
||||
|
_namingPolicy = namingPolicy; |
||||
|
_allowIntegerValues = allowIntegerValues; |
||||
|
} |
||||
|
|
||||
|
public override bool CanConvert(Type typeToConvert) |
||||
|
{ |
||||
|
return typeToConvert.IsEnum; |
||||
|
} |
||||
|
|
||||
|
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) |
||||
|
{ |
||||
|
return (JsonConverter) Activator.CreateInstance( |
||||
|
typeof(AbpStringToEnumConverter<>).MakeGenericType(typeToConvert), |
||||
|
BindingFlags.Instance | BindingFlags.Public, |
||||
|
binder: null, |
||||
|
new object[] { _namingPolicy, _allowIntegerValues }, |
||||
|
culture: null)!; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,63 @@ |
|||||
|
using Shouldly; |
||||
|
using Volo.Abp.Json.SystemTextJson; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Abp.Json |
||||
|
{ |
||||
|
public class AbpSystemTextJsonSerializerProvider_Tests : AbpJsonTestBase |
||||
|
{ |
||||
|
private readonly AbpSystemTextJsonSerializerProvider _jsonSerializer; |
||||
|
|
||||
|
public AbpSystemTextJsonSerializerProvider_Tests() |
||||
|
{ |
||||
|
_jsonSerializer = GetRequiredService<AbpSystemTextJsonSerializerProvider>(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Serialize_Deserialize_With_Boolean() |
||||
|
{ |
||||
|
var json = "{\"name\":\"abp\",\"IsDeleted\":\"fAlSe\"}"; |
||||
|
var file = _jsonSerializer.Deserialize<FileWithBoolean>(json); |
||||
|
file.Name.ShouldBe("abp"); |
||||
|
file.IsDeleted.ShouldBeFalse(); |
||||
|
|
||||
|
file.IsDeleted = false; |
||||
|
var newJson = _jsonSerializer.Serialize(file); |
||||
|
newJson.ShouldBe("{\"name\":\"abp\",\"isDeleted\":false}"); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Serialize_Deserialize_With_Enum() |
||||
|
{ |
||||
|
var json = "{\"name\":\"abp\",\"type\":\"Exe\"}"; |
||||
|
var file = _jsonSerializer.Deserialize<FileWithEnum>(json); |
||||
|
file.Name.ShouldBe("abp"); |
||||
|
file.Type.ShouldBe(FileType.Exe); |
||||
|
|
||||
|
var newJson = _jsonSerializer.Serialize(file); |
||||
|
newJson.ShouldBe("{\"name\":\"abp\",\"type\":2}"); |
||||
|
} |
||||
|
|
||||
|
class FileWithBoolean |
||||
|
{ |
||||
|
public string Name { get; set; } |
||||
|
|
||||
|
public bool IsDeleted { get; set; } |
||||
|
|
||||
|
} |
||||
|
|
||||
|
class FileWithEnum |
||||
|
{ |
||||
|
public string Name { get; set; } |
||||
|
|
||||
|
public FileType Type { get; set; } |
||||
|
} |
||||
|
|
||||
|
|
||||
|
enum FileType |
||||
|
{ |
||||
|
Zip = 0, |
||||
|
Exe = 2 |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1 +1,48 @@ |
|||||
|
.spinner { |
||||
|
width: 40px; |
||||
|
height: 40px; |
||||
|
display: block; |
||||
|
position: fixed; |
||||
|
top: calc( 50% - ( 40px / 2) ); |
||||
|
right: calc( 50% - ( 40px / 2) ); |
||||
|
} |
||||
|
|
||||
|
.double-bounce1, .double-bounce2 { |
||||
|
width: 100%; |
||||
|
height: 100%; |
||||
|
border-radius: 50%; |
||||
|
background-color: #333; |
||||
|
opacity: 0.6; |
||||
|
position: absolute; |
||||
|
top: 0; |
||||
|
left: 0; |
||||
|
-webkit-animation: sk-bounce 2.0s infinite ease-in-out; |
||||
|
animation: sk-bounce 2.0s infinite ease-in-out; |
||||
|
} |
||||
|
|
||||
|
.double-bounce2 { |
||||
|
-webkit-animation-delay: -1.0s; |
||||
|
animation-delay: -1.0s; |
||||
|
} |
||||
|
|
||||
|
@-webkit-keyframes sk-bounce { |
||||
|
0%, 100% { |
||||
|
-webkit-transform: scale(0.0) |
||||
|
} |
||||
|
|
||||
|
50% { |
||||
|
-webkit-transform: scale(1.0) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@keyframes sk-bounce { |
||||
|
0%, 100% { |
||||
|
transform: scale(0.0); |
||||
|
-webkit-transform: scale(0.0); |
||||
|
} |
||||
|
|
||||
|
50% { |
||||
|
transform: scale(1.0); |
||||
|
-webkit-transform: scale(1.0); |
||||
|
} |
||||
|
} |
||||
|
|||||
Loading…
Reference in new issue