Skip to content

Commit

Permalink
将 Newtonsoft.Json 更换为 System.Text.Json
Browse files Browse the repository at this point in the history
  • Loading branch information
欧俊 committed Dec 14, 2022
1 parent 84a50de commit 4d89965
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System;
using System.Threading.Tasks;

Expand Down
15 changes: 11 additions & 4 deletions src/RabbitMQ.EventBus.AspNetCore/Extensions/DynamicExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ internal static class DynamicExtensions
/// <typeparam name="TMessage"></typeparam>
/// <param name="message"></param>
/// <returns></returns>
public static string Serialize<TMessage>(this TMessage message)
public static string Serialize<TMessage>(this TMessage message) => JsonSerializer.Serialize(message, new JsonSerializerOptions
{
return JsonConvert.SerializeObject(message);
}
PropertyNameCaseInsensitive = true,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
NumberHandling = JsonNumberHandling.AllowReadingFromString
});
/// <summary>
///
/// </summary>
Expand All @@ -36,7 +38,12 @@ public static TResponse Deserialize<TResponse>(this string message)
{
try
{
return JsonConvert.DeserializeObject<TResponse>(message);
return JsonSerializer.Deserialize<TResponse>(message, new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
NumberHandling = JsonNumberHandling.AllowReadingFromString
});
}
catch
{
Expand Down
5 changes: 3 additions & 2 deletions src/RabbitMQ.EventBus.AspNetCore/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.DependencyInjection.Extensions;
global using Microsoft.Extensions.Logging;
global using Newtonsoft.Json;
global using Polly;
global using Polly.Retry;
global using RabbitMQ.Client;
Expand All @@ -21,6 +20,8 @@
global using System.Linq;
global using System.Net.Sockets;
global using System.Text;
global using System.Text.Encodings.Web;
global using System.Text.Json;
global using System.Text.Json.Serialization;
global using System.Threading;
global using System.Threading.Tasks;

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="Polly" Version="7.2.3" />
<PackageReference Include="RabbitMQ.Client" Version="6.4.0" />
</ItemGroup>
Expand Down

0 comments on commit 4d89965

Please sign in to comment.