소스 검색

Change System.Text.Json to Json.NET

master
Savorboard 5 년 전
부모
커밋
02c0eefd07
5개의 변경된 파일24개의 추가작업 그리고 12개의 파일을 삭제
  1. +2
    -2
      src/DotNetCore.CAP.Kafka/IConnectionPool.Default.cs
  2. +1
    -1
      src/DotNetCore.CAP/DotNetCore.CAP.csproj
  3. +10
    -4
      src/DotNetCore.CAP/Serialization/ISerializer.JsonUtf8.cs
  4. +4
    -1
      src/DotNetCore.CAP/Serialization/ISerializer.cs
  5. +7
    -4
      src/DotNetCore.CAP/Serialization/StringSerializer.cs

+ 2
- 2
src/DotNetCore.CAP.Kafka/IConnectionPool.Default.cs 파일 보기

@@ -3,11 +3,11 @@

using System;
using System.Collections.Concurrent;
using System.Text.Json;
using System.Threading;
using Confluent.Kafka;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;

namespace DotNetCore.CAP.Kafka
{
@@ -24,7 +24,7 @@ namespace DotNetCore.CAP.Kafka
_producerPool = new ConcurrentQueue<IProducer<string, byte[]>>();
_maxSize = _options.ConnectionPoolSize;

logger.LogDebug("Kafka configuration of CAP :\r\n {0}", JsonSerializer.Serialize(_options.AsKafkaConfig()));
logger.LogDebug("Kafka configuration of CAP :\r\n {0}", JsonConvert.SerializeObject(_options.AsKafkaConfig()));
}

public string ServersAddress => _options.Servers;


+ 1
- 1
src/DotNetCore.CAP/DotNetCore.CAP.csproj 파일 보기

@@ -13,8 +13,8 @@
<PackageReference Include="JetBrains.Annotations" Version="2019.1.3" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="3.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0" />
<PackageReference Include="System.Text.Json" Version="4.6.0" />
</ItemGroup>
</Project>

+ 10
- 4
src/DotNetCore.CAP/Serialization/ISerializer.JsonUtf8.cs 파일 보기

@@ -1,7 +1,11 @@
using System;
// Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System.Text;
using System.Threading.Tasks;
using DotNetCore.CAP.Messages;
using System.Text.Json;
using Newtonsoft.Json;

namespace DotNetCore.CAP.Serialization
{
@@ -9,7 +13,8 @@ namespace DotNetCore.CAP.Serialization
{
public Task<TransportMessage> SerializeAsync(Message message)
{
return Task.FromResult(new TransportMessage(message.Headers, JsonSerializer.SerializeToUtf8Bytes(message.Value)));
var json = JsonConvert.SerializeObject(message.Value);
return Task.FromResult(new TransportMessage(message.Headers, Encoding.UTF8.GetBytes(json)));
}

public Task<Message> DeserializeAsync(TransportMessage transportMessage, Type valueType)
@@ -19,7 +24,8 @@ namespace DotNetCore.CAP.Serialization
return Task.FromResult(new Message(transportMessage.Headers, null));
}

return Task.FromResult(new Message(transportMessage.Headers, JsonSerializer.Deserialize(transportMessage.Body, valueType)));
var json = Encoding.UTF8.GetString(transportMessage.Body);
return Task.FromResult(new Message(transportMessage.Headers, JsonConvert.DeserializeObject(json, valueType)));
}
}
}

+ 4
- 1
src/DotNetCore.CAP/Serialization/ISerializer.cs 파일 보기

@@ -1,4 +1,7 @@
using System;
// Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System.Threading.Tasks;
using DotNetCore.CAP.Messages;
using JetBrains.Annotations;


+ 7
- 4
src/DotNetCore.CAP/Serialization/StringSerializer.cs 파일 보기

@@ -1,5 +1,8 @@
using DotNetCore.CAP.Messages;
using System.Text.Json;
// Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using DotNetCore.CAP.Messages;
using Newtonsoft.Json;

namespace DotNetCore.CAP.Serialization
{
@@ -7,12 +10,12 @@ namespace DotNetCore.CAP.Serialization
{
public static string Serialize(Message message)
{
return JsonSerializer.Serialize(message);
return JsonConvert.SerializeObject(message);
}

public static Message DeSerialize(string json)
{
return JsonSerializer.Deserialize<Message>(json);
return JsonConvert.DeserializeObject<Message>(json);
}
}
}

불러오는 중...
취소
저장