@@ -5,6 +5,7 @@ using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | using System.Linq; | ||||
using System.Text; | using System.Text; | ||||
using System.Text.Json; | |||||
using System.Threading; | using System.Threading; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
using Amazon.SimpleNotificationService; | using Amazon.SimpleNotificationService; | ||||
@@ -14,7 +15,6 @@ using Amazon.SQS.Model; | |||||
using DotNetCore.CAP.Messages; | using DotNetCore.CAP.Messages; | ||||
using DotNetCore.CAP.Transport; | using DotNetCore.CAP.Transport; | ||||
using Microsoft.Extensions.Options; | using Microsoft.Extensions.Options; | ||||
using Newtonsoft.Json; | |||||
using Headers = DotNetCore.CAP.Messages.Headers; | using Headers = DotNetCore.CAP.Messages.Headers; | ||||
namespace DotNetCore.CAP.AmazonSQS | namespace DotNetCore.CAP.AmazonSQS | ||||
@@ -83,7 +83,7 @@ namespace DotNetCore.CAP.AmazonSQS | |||||
if (response.Messages.Count == 1) | if (response.Messages.Count == 1) | ||||
{ | { | ||||
var messageObj = JsonConvert.DeserializeObject<SQSReceivedMessage>(response.Messages[0].Body); | |||||
var messageObj = JsonSerializer.Deserialize<SQSReceivedMessage>(response.Messages[0].Body); | |||||
var header = messageObj.MessageAttributes.ToDictionary(x => x.Key, x => x.Value.Value); | var header = messageObj.MessageAttributes.ToDictionary(x => x.Key, x => x.Value.Value); | ||||
var body = messageObj.Message; | var body = messageObj.Message; | ||||
@@ -40,8 +40,6 @@ | |||||
<ItemGroup> | <ItemGroup> | ||||
<FrameworkReference Include="Microsoft.AspNetCore.App" /> | <FrameworkReference Include="Microsoft.AspNetCore.App" /> | ||||
<PackageReference Include="Consul" Version="1.6.1.1" /> | <PackageReference Include="Consul" Version="1.6.1.1" /> | ||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" /> | |||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" /> | |||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
@@ -2,10 +2,8 @@ | |||||
// Licensed under the MIT License. See License.txt in the project root for license information. | // Licensed under the MIT License. See License.txt in the project root for license information. | ||||
using System; | using System; | ||||
using System.Threading.Tasks; | |||||
using Newtonsoft.Json; | |||||
using Newtonsoft.Json.Converters; | |||||
using Newtonsoft.Json.Serialization; | |||||
using System.Text.Json; | |||||
using System.Threading.Tasks; | |||||
namespace DotNetCore.CAP.Dashboard | namespace DotNetCore.CAP.Dashboard | ||||
{ | { | ||||
@@ -30,19 +28,8 @@ namespace DotNetCore.CAP.Dashboard | |||||
if (_command != null) | if (_command != null) | ||||
{ | { | ||||
var result = _command(context); | var result = _command(context); | ||||
var settings = new JsonSerializerSettings | |||||
{ | |||||
ContractResolver = new CamelCasePropertyNamesContractResolver(), | |||||
Converters = new JsonConverter[] | |||||
{ | |||||
new StringEnumConverter | |||||
{ | |||||
NamingStrategy = new CamelCaseNamingStrategy() | |||||
} | |||||
} | |||||
}; | |||||
serialized = JsonConvert.SerializeObject(result, settings); | |||||
serialized = JsonSerializer.Serialize(result); | |||||
} | } | ||||
if (_jsonCommand != null) | if (_jsonCommand != null) | ||||
@@ -3,10 +3,8 @@ | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | using System.Linq; | ||||
using System.Text.Json; | |||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
using Newtonsoft.Json; | |||||
using Newtonsoft.Json.Converters; | |||||
using Newtonsoft.Json.Serialization; | |||||
namespace DotNetCore.CAP.Dashboard | namespace DotNetCore.CAP.Dashboard | ||||
{ | { | ||||
@@ -26,19 +24,8 @@ namespace DotNetCore.CAP.Dashboard | |||||
var value = metric.Func(page); | var value = metric.Func(page); | ||||
result.Add(metric.Name, value); | result.Add(metric.Name, value); | ||||
} | } | ||||
var settings = new JsonSerializerSettings | |||||
{ | |||||
ContractResolver = new CamelCasePropertyNamesContractResolver(), | |||||
Converters = new JsonConverter[] | |||||
{ | |||||
new StringEnumConverter | |||||
{ | |||||
NamingStrategy = new CamelCaseNamingStrategy() | |||||
} | |||||
} | |||||
}; | |||||
var serialized = JsonConvert.SerializeObject(result, settings); | |||||
var serialized = JsonSerializer.Serialize(result); | |||||
context.Response.ContentType = "application/json"; | context.Response.ContentType = "application/json"; | ||||
await context.Response.WriteAsync(serialized); | await context.Response.WriteAsync(serialized); | ||||
@@ -1,8 +1,8 @@ | |||||
@* Generator: Template TypeVisibility: Internal GeneratePrettyNames: True *@ | @* Generator: Template TypeVisibility: Internal GeneratePrettyNames: True *@ | ||||
@using System.Text.Json | |||||
@using DotNetCore.CAP.Dashboard.Pages | @using DotNetCore.CAP.Dashboard.Pages | ||||
@using DotNetCore.CAP.Dashboard.Resources | @using DotNetCore.CAP.Dashboard.Resources | ||||
@using DotNetCore.CAP.Messages | @using DotNetCore.CAP.Messages | ||||
@using Newtonsoft.Json | |||||
@inherits DotNetCore.CAP.Dashboard.RazorPage | @inherits DotNetCore.CAP.Dashboard.RazorPage | ||||
@{ | @{ | ||||
Layout = new LayoutPage(Strings.HomePage_Title); | Layout = new LayoutPage(Strings.HomePage_Title); | ||||
@@ -52,12 +52,12 @@ | |||||
</h3> | </h3> | ||||
<div id="historyGraph" | <div id="historyGraph" | ||||
data-published-succeeded="@JsonConvert.SerializeObject(publishedSucceeded)" | |||||
data-published-failed="@JsonConvert.SerializeObject(publishedFailed)" | |||||
data-published-succeeded="@JsonSerializer.Serialize(publishedSucceeded)" | |||||
data-published-failed="@JsonSerializer.Serialize(publishedFailed)" | |||||
data-published-succeeded-string="@Strings.HomePage_GraphHover_PSucceeded" | data-published-succeeded-string="@Strings.HomePage_GraphHover_PSucceeded" | ||||
data-published-failed-string="@Strings.HomePage_GraphHover_PFailed" | data-published-failed-string="@Strings.HomePage_GraphHover_PFailed" | ||||
data-received-succeeded="@JsonConvert.SerializeObject(receivedSucceeded)" | |||||
data-received-failed="@JsonConvert.SerializeObject(receivedFailed)" | |||||
data-received-succeeded="@JsonSerializer.Serialize(receivedSucceeded)" | |||||
data-received-failed="@JsonSerializer.Serialize(receivedFailed)" | |||||
data-received-succeeded-string="@Strings.HomePage_GraphHover_RSucceeded" | data-received-succeeded-string="@Strings.HomePage_GraphHover_RSucceeded" | ||||
data-received-failed-string="@Strings.HomePage_GraphHover_RFailed"> | data-received-failed-string="@Strings.HomePage_GraphHover_RFailed"> | ||||
</div> | </div> | ||||
@@ -35,7 +35,7 @@ namespace DotNetCore.CAP.Dashboard.Pages | |||||
#line hidden | #line hidden | ||||
#line 5 "..\..\Pages\HomePage.cshtml" | #line 5 "..\..\Pages\HomePage.cshtml" | ||||
using Newtonsoft.Json; | |||||
using System.Text.Json; | |||||
#line default | #line default | ||||
#line hidden | #line hidden | ||||
@@ -252,7 +252,7 @@ WriteLiteral("\r\n </h3>\r\n\r\n <div id=\"historyGraph\"\r\n | |||||
#line 55 "..\..\Pages\HomePage.cshtml" | #line 55 "..\..\Pages\HomePage.cshtml" | ||||
Write(JsonConvert.SerializeObject(publishedSucceeded)); | |||||
Write(JsonSerializer.Serialize(publishedSucceeded)); | |||||
#line default | #line default | ||||
@@ -262,7 +262,7 @@ WriteLiteral("\"\r\n data-published-failed=\""); | |||||
#line 56 "..\..\Pages\HomePage.cshtml" | #line 56 "..\..\Pages\HomePage.cshtml" | ||||
Write(JsonConvert.SerializeObject(publishedFailed)); | |||||
Write(JsonSerializer.Serialize(publishedFailed)); | |||||
#line default | #line default | ||||
@@ -292,7 +292,7 @@ WriteLiteral("\"\r\n data-received-succeeded=\""); | |||||
#line 59 "..\..\Pages\HomePage.cshtml" | #line 59 "..\..\Pages\HomePage.cshtml" | ||||
Write(JsonConvert.SerializeObject(receivedSucceeded)); | |||||
Write(JsonSerializer.Serialize(receivedSucceeded)); | |||||
#line default | #line default | ||||
@@ -302,7 +302,7 @@ WriteLiteral("\"\r\n data-received-failed=\""); | |||||
#line 60 "..\..\Pages\HomePage.cshtml" | #line 60 "..\..\Pages\HomePage.cshtml" | ||||
Write(JsonConvert.SerializeObject(receivedFailed)); | |||||
Write(JsonSerializer.Serialize(receivedFailed)); | |||||
#line default | #line default | ||||
@@ -13,9 +13,9 @@ | |||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="5.0.0" /> | <PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="5.0.0" /> | ||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" /> | <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" /> | ||||
<PackageReference Include="Microsoft.Extensions.Options" Version="5.0.0" /> | <PackageReference Include="Microsoft.Extensions.Options" Version="5.0.0" /> | ||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> | |||||
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="5.0.0" /> | <PackageReference Include="System.Diagnostics.DiagnosticSource" Version="5.0.0" /> | ||||
<PackageReference Include="System.Threading.Channels" Version="5.0.0" /> | <PackageReference Include="System.Threading.Channels" Version="5.0.0" /> | ||||
<PackageReference Include="System.Text.Json" Version="5.0.0" /> | |||||
</ItemGroup> | </ItemGroup> | ||||
</Project> | </Project> |
@@ -2,11 +2,10 @@ | |||||
// Licensed under the MIT License. See License.txt in the project root for license information. | // Licensed under the MIT License. See License.txt in the project root for license information. | ||||
using System; | using System; | ||||
using System.Text; | |||||
using System.Buffers; | |||||
using System.Text.Json; | |||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
using DotNetCore.CAP.Messages; | using DotNetCore.CAP.Messages; | ||||
using Newtonsoft.Json; | |||||
using Newtonsoft.Json.Linq; | |||||
namespace DotNetCore.CAP.Serialization | namespace DotNetCore.CAP.Serialization | ||||
{ | { | ||||
@@ -24,8 +23,8 @@ namespace DotNetCore.CAP.Serialization | |||||
return Task.FromResult(new TransportMessage(message.Headers, null)); | return Task.FromResult(new TransportMessage(message.Headers, null)); | ||||
} | } | ||||
var json = JsonConvert.SerializeObject(message.Value); | |||||
return Task.FromResult(new TransportMessage(message.Headers, Encoding.UTF8.GetBytes(json))); | |||||
var jsonBytes = JsonSerializer.SerializeToUtf8Bytes(message.Value); | |||||
return Task.FromResult(new TransportMessage(message.Headers, jsonBytes)); | |||||
} | } | ||||
public Task<Message> DeserializeAsync(TransportMessage transportMessage, Type valueType) | public Task<Message> DeserializeAsync(TransportMessage transportMessage, Type valueType) | ||||
@@ -35,32 +34,39 @@ namespace DotNetCore.CAP.Serialization | |||||
return Task.FromResult(new Message(transportMessage.Headers, null)); | return Task.FromResult(new Message(transportMessage.Headers, null)); | ||||
} | } | ||||
var json = Encoding.UTF8.GetString(transportMessage.Body); | |||||
return Task.FromResult(new Message(transportMessage.Headers, JsonConvert.DeserializeObject(json, valueType))); | |||||
var obj = JsonSerializer.Deserialize(transportMessage.Body, valueType); | |||||
return Task.FromResult(new Message(transportMessage.Headers, obj)); | |||||
} | } | ||||
public string Serialize(Message message) | public string Serialize(Message message) | ||||
{ | { | ||||
return JsonConvert.SerializeObject(message); | |||||
return JsonSerializer.Serialize(message); | |||||
} | } | ||||
public Message Deserialize(string json) | public Message Deserialize(string json) | ||||
{ | { | ||||
return JsonConvert.DeserializeObject<Message>(json); | |||||
return JsonSerializer.Deserialize<Message>(json); | |||||
} | } | ||||
public object Deserialize(object value, Type valueType) | public object Deserialize(object value, Type valueType) | ||||
{ | { | ||||
if (value is JToken jToken) | |||||
if (value is JsonElement jToken) | |||||
{ | { | ||||
return jToken.ToObject(valueType); | |||||
var bufferWriter = new ArrayBufferWriter<byte>(); | |||||
using (var writer = new Utf8JsonWriter(bufferWriter)) | |||||
{ | |||||
jToken.WriteTo(writer); | |||||
} | |||||
return JsonSerializer.Deserialize(bufferWriter.WrittenSpan, valueType); | |||||
} | } | ||||
throw new NotSupportedException("Type is not of type JToken"); | throw new NotSupportedException("Type is not of type JToken"); | ||||
} | } | ||||
public bool IsJsonType(object jsonObject) | public bool IsJsonType(object jsonObject) | ||||
{ | { | ||||
return jsonObject is JToken; | |||||
return jsonObject is JsonElement; | |||||
} | } | ||||
} | |||||
} | |||||
} | } |