From de6fe6a2a2d1ee5fad18263908bc89f9d575cafa Mon Sep 17 00:00:00 2001 From: Phong Nguyen Date: Tue, 23 Nov 2021 09:08:30 +0700 Subject: [PATCH] (#110) Removing Newtonsoft.Json --- .../AuditLog/AuditLogCommandDecorator.cs | 4 +- .../AuditLog/AuditLogQueryDecorator.cs | 4 +- .../ClassifiedAds.CrossCuttingConcerns.csproj | 24 ++++++------ .../ExtensionMethods/CloningExtensions.cs | 12 ++---- .../ExtensionMethods/HttpContentExtensions.cs | 22 ++++++----- .../ExtensionMethods/ObjectExtensions.cs | 4 +- .../ClassifiedAds.Domain.csproj | 34 ++++++++-------- .../Infrastructure/MessageBrokers/Message.cs | 6 +-- .../ClassifiedAds.Infrastructure.csproj | 39 +++++++++---------- .../Interceptors/ErrorCatchingInterceptor.cs | 10 ++++- .../Interceptors/LoggingInterceptor.cs | 11 +++++- .../AzureEventGrid/AzureEventGridSender.cs | 4 +- .../AzureEventHub/AzureEventHubReceiver.cs | 4 +- .../AzureEventHub/AzureEventHubSender.cs | 4 +- .../AzureQueue/AzureQueueReceiver.cs | 4 +- .../AzureQueue/AzureQueueSender.cs | 4 +- .../AzureServiceBusReceiver.cs | 4 +- .../AzureServiceBus/AzureServiceBusSender.cs | 4 +- .../AzureServiceBusSubscriptionReceiver.cs | 4 +- .../AzureServiceBusTopicSender.cs | 4 +- .../MessageBrokers/Kafka/KafkaReceiver.cs | 4 +- .../MessageBrokers/Kafka/KafkaSender.cs | 4 +- .../RabbitMQ/RabbitMQReceiver.cs | 4 +- .../MessageBrokers/RabbitMQ/RabbitMQSender.cs | 4 +- .../Controllers/ApiResourceController.cs | 4 +- .../Controllers/ApiScopeController.cs | 4 +- .../Controllers/IdentityResourceController.cs | 12 +++--- .../Models/ClientModels/ClientModel.cs | 4 +- .../Diagnostics/DiagnosticsViewModel.cs | 4 +- .../TagHelpers/PickerTagHelper.cs | 7 +--- .../Controllers/ProductsController.cs | 4 +- .../Controllers/FilesController.cs | 4 +- .../AuditLog/AuditLogCommandDecorator.cs | 4 +- .../AuditLog/AuditLogQueryDecorator.cs | 4 +- .../ClassifiedAds.CrossCuttingConcerns.csproj | 24 ++++++------ .../ExtensionMethods/CloningExtensions.cs | 12 ++---- .../ExtensionMethods/HttpContentExtensions.cs | 22 ++++++----- .../ExtensionMethods/ObjectExtensions.cs | 4 +- .../ClassifiedAds.Domain.csproj | 34 ++++++++-------- .../Infrastructure/MessageBrokers/Message.cs | 6 +-- .../Controllers/ApiResourceController.cs | 4 +- .../Controllers/ApiScopeController.cs | 4 +- .../Controllers/IdentityResourceController.cs | 12 +++--- .../Models/ClientModels/ClientModel.cs | 4 +- .../Diagnostics/DiagnosticsViewModel.cs | 4 +- .../TagHelpers/PickerTagHelper.cs | 7 +--- .../ClassifiedAds.Infrastructure.csproj | 1 - .../Interceptors/ErrorCatchingInterceptor.cs | 10 ++++- .../Interceptors/LoggingInterceptor.cs | 11 +++++- .../AzureEventGrid/AzureEventGridSender.cs | 4 +- .../AzureEventHub/AzureEventHubReceiver.cs | 4 +- .../AzureEventHub/AzureEventHubSender.cs | 4 +- .../AzureQueue/AzureQueueReceiver.cs | 4 +- .../AzureQueue/AzureQueueSender.cs | 4 +- .../AzureServiceBusReceiver.cs | 4 +- .../AzureServiceBus/AzureServiceBusSender.cs | 4 +- .../AzureServiceBusSubscriptionReceiver.cs | 4 +- .../AzureServiceBusTopicSender.cs | 4 +- .../MessageBrokers/Kafka/KafkaReceiver.cs | 4 +- .../MessageBrokers/Kafka/KafkaSender.cs | 4 +- .../RabbitMQ/RabbitMQReceiver.cs | 4 +- .../MessageBrokers/RabbitMQ/RabbitMQSender.cs | 4 +- .../Controllers/ProductsController.cs | 4 +- .../Controllers/FilesController.cs | 4 +- .../AuditLog/AuditLogCommandDecorator.cs | 4 +- .../AuditLog/AuditLogQueryDecorator.cs | 4 +- .../ClassifiedAds.CrossCuttingConcerns.csproj | 2 +- .../ExtensionMethods/CloningExtensions.cs | 12 ++---- .../ExtensionMethods/HttpContentExtensions.cs | 22 ++++++----- .../ExtensionMethods/ObjectExtensions.cs | 4 +- .../ClassifiedAds.Domain.csproj | 34 ++++++++-------- .../Infrastructure/MessageBrokers/Message.cs | 6 +-- .../Controllers/ApiResourceController.cs | 4 +- .../Controllers/ApiScopeController.cs | 4 +- .../Controllers/IdentityResourceController.cs | 12 +++--- .../Models/ClientModels/ClientModel.cs | 4 +- .../Diagnostics/DiagnosticsViewModel.cs | 4 +- .../TagHelpers/PickerTagHelper.cs | 7 +--- .../ClassifiedAds.Infrastructure.csproj | 1 - .../Interceptors/ErrorCatchingInterceptor.cs | 10 ++++- .../Interceptors/LoggingInterceptor.cs | 11 +++++- .../AzureEventGrid/AzureEventGridSender.cs | 4 +- .../AzureEventHub/AzureEventHubReceiver.cs | 4 +- .../AzureEventHub/AzureEventHubSender.cs | 4 +- .../AzureQueue/AzureQueueReceiver.cs | 4 +- .../AzureQueue/AzureQueueSender.cs | 4 +- .../AzureServiceBusReceiver.cs | 4 +- .../AzureServiceBus/AzureServiceBusSender.cs | 4 +- .../AzureServiceBusSubscriptionReceiver.cs | 4 +- .../AzureServiceBusTopicSender.cs | 4 +- .../MessageBrokers/Kafka/KafkaReceiver.cs | 4 +- .../MessageBrokers/Kafka/KafkaSender.cs | 4 +- .../RabbitMQ/RabbitMQReceiver.cs | 4 +- .../MessageBrokers/RabbitMQ/RabbitMQSender.cs | 4 +- .../Controllers/FilesController.cs | 4 +- .../Controllers/ProductsController.cs | 4 +- 96 files changed, 353 insertions(+), 344 deletions(-) diff --git a/src/Microservices/Common/ClassifiedAds.Application/Decorators/AuditLog/AuditLogCommandDecorator.cs b/src/Microservices/Common/ClassifiedAds.Application/Decorators/AuditLog/AuditLogCommandDecorator.cs index bc9090e36..91e47f012 100644 --- a/src/Microservices/Common/ClassifiedAds.Application/Decorators/AuditLog/AuditLogCommandDecorator.cs +++ b/src/Microservices/Common/ClassifiedAds.Application/Decorators/AuditLog/AuditLogCommandDecorator.cs @@ -1,7 +1,7 @@ using System; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; -using Newtonsoft.Json; namespace ClassifiedAds.Application.Decorators.AuditLog { @@ -18,7 +18,7 @@ public AuditLogCommandDecorator(ICommandHandler handler) public async Task HandleAsync(TCommand command, CancellationToken cancellationToken = default) { - var commandJson = JsonConvert.SerializeObject(command); + var commandJson = JsonSerializer.Serialize(command); Console.WriteLine($"Command of type {command.GetType().Name}: {commandJson}"); await _handler.HandleAsync(command, cancellationToken); } diff --git a/src/Microservices/Common/ClassifiedAds.Application/Decorators/AuditLog/AuditLogQueryDecorator.cs b/src/Microservices/Common/ClassifiedAds.Application/Decorators/AuditLog/AuditLogQueryDecorator.cs index 5f2b57d4c..554e10316 100644 --- a/src/Microservices/Common/ClassifiedAds.Application/Decorators/AuditLog/AuditLogQueryDecorator.cs +++ b/src/Microservices/Common/ClassifiedAds.Application/Decorators/AuditLog/AuditLogQueryDecorator.cs @@ -1,7 +1,7 @@ using System; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; -using Newtonsoft.Json; namespace ClassifiedAds.Application.Decorators.AuditLog { @@ -18,7 +18,7 @@ public AuditLogQueryDecorator(IQueryHandler handler) public Task HandleAsync(TQuery query, CancellationToken cancellationToken = default) { - string queryJson = JsonConvert.SerializeObject(query); + string queryJson = JsonSerializer.Serialize(query); Console.WriteLine($"Query of type {query.GetType().Name}: {queryJson}"); return _handler.HandleAsync(query, cancellationToken); } diff --git a/src/Microservices/Common/ClassifiedAds.CrossCuttingConcerns/ClassifiedAds.CrossCuttingConcerns.csproj b/src/Microservices/Common/ClassifiedAds.CrossCuttingConcerns/ClassifiedAds.CrossCuttingConcerns.csproj index 2abe3ca99..f9ae43c75 100644 --- a/src/Microservices/Common/ClassifiedAds.CrossCuttingConcerns/ClassifiedAds.CrossCuttingConcerns.csproj +++ b/src/Microservices/Common/ClassifiedAds.CrossCuttingConcerns/ClassifiedAds.CrossCuttingConcerns.csproj @@ -1,17 +1,17 @@  - - net6.0 - ClassifiedAds.CrossCuttingConcerns - ClassifiedAds.CrossCuttingConcerns.ruleset - + + net6.0 + ClassifiedAds.CrossCuttingConcerns + ClassifiedAds.CrossCuttingConcerns.ruleset + - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/src/Microservices/Common/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/CloningExtensions.cs b/src/Microservices/Common/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/CloningExtensions.cs index a67210374..4410be804 100644 --- a/src/Microservices/Common/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/CloningExtensions.cs +++ b/src/Microservices/Common/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/CloningExtensions.cs @@ -1,5 +1,5 @@ -using Newtonsoft.Json; -using System.Reflection; +using System.Reflection; +using System.Text.Json; namespace ClassifiedAds.CrossCuttingConcerns.ExtensionMethods { @@ -28,13 +28,7 @@ public static T DeepCloneJson(this T source) return default(T); } - // initialize inner objects individually - // for example in default constructor some list property initialized with some values, - // but in 'source' these items are cleaned - - // without ObjectCreationHandling.Replace default constructor values will be added to result - var deserializeSettings = new JsonSerializerSettings { ObjectCreationHandling = ObjectCreationHandling.Replace }; - - return JsonConvert.DeserializeObject(JsonConvert.SerializeObject(source), deserializeSettings); + return JsonSerializer.Deserialize(JsonSerializer.Serialize(source)); } } } diff --git a/src/Microservices/Common/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/HttpContentExtensions.cs b/src/Microservices/Common/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/HttpContentExtensions.cs index 2c7d3feb2..3b6b4c707 100644 --- a/src/Microservices/Common/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/HttpContentExtensions.cs +++ b/src/Microservices/Common/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/HttpContentExtensions.cs @@ -1,7 +1,6 @@ -using Newtonsoft.Json; -using System.IO; -using System.Net.Http; +using System.Net.Http; using System.Net.Http.Headers; +using System.Text.Json; using System.Threading.Tasks; namespace ClassifiedAds.CrossCuttingConcerns.ExtensionMethods @@ -10,19 +9,22 @@ public static class HttpContentExtensions { public static async Task ReadAs(this HttpContent httpContent) { - using (var streamReader = new StreamReader(await httpContent.ReadAsStreamAsync())) + var json = await httpContent.ReadAsStringAsync(); + + if (string.IsNullOrWhiteSpace(json)) { - using (var jsonTextReader = new JsonTextReader(streamReader)) - { - var jsonSerializer = new JsonSerializer(); - return jsonSerializer.Deserialize(jsonTextReader); - } + return default; } + + return JsonSerializer.Deserialize(json, new JsonSerializerOptions + { + PropertyNameCaseInsensitive = true, + }); } public static StringContent AsStringContent(this object obj, string contentType) { - var content = new StringContent(JsonConvert.SerializeObject(obj)); + var content = new StringContent(JsonSerializer.Serialize(obj)); content.Headers.ContentType = new MediaTypeHeaderValue(contentType); return content; } diff --git a/src/Microservices/Common/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/ObjectExtensions.cs b/src/Microservices/Common/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/ObjectExtensions.cs index 7edad2dc1..1f5888fa2 100644 --- a/src/Microservices/Common/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/ObjectExtensions.cs +++ b/src/Microservices/Common/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/ObjectExtensions.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json; +using System.Text.Json; namespace ClassifiedAds.CrossCuttingConcerns.ExtensionMethods { @@ -6,7 +6,7 @@ public static class ObjectExtensions { public static string AsJsonString(this object obj) { - var content = JsonConvert.SerializeObject(obj, Formatting.Indented); + var content = JsonSerializer.Serialize(obj, new JsonSerializerOptions { WriteIndented = true }); return content; } } diff --git a/src/Microservices/Common/ClassifiedAds.Domain/ClassifiedAds.Domain.csproj b/src/Microservices/Common/ClassifiedAds.Domain/ClassifiedAds.Domain.csproj index 907948686..36270ee4b 100644 --- a/src/Microservices/Common/ClassifiedAds.Domain/ClassifiedAds.Domain.csproj +++ b/src/Microservices/Common/ClassifiedAds.Domain/ClassifiedAds.Domain.csproj @@ -1,23 +1,23 @@  - - net6.0 - ClassifiedAds.Domain.ruleset - + + net6.0 + ClassifiedAds.Domain.ruleset + - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + - - - + + + diff --git a/src/Microservices/Common/ClassifiedAds.Domain/Infrastructure/MessageBrokers/Message.cs b/src/Microservices/Common/ClassifiedAds.Domain/Infrastructure/MessageBrokers/Message.cs index 544ce23c2..33f456c0c 100644 --- a/src/Microservices/Common/ClassifiedAds.Domain/Infrastructure/MessageBrokers/Message.cs +++ b/src/Microservices/Common/ClassifiedAds.Domain/Infrastructure/MessageBrokers/Message.cs @@ -1,5 +1,5 @@ -using Newtonsoft.Json; -using System.Text; +using System.Text; +using System.Text.Json; namespace ClassifiedAds.Domain.Infrastructure.MessageBrokers { @@ -11,7 +11,7 @@ public class Message public string SerializeObject() { - return JsonConvert.SerializeObject(this); + return JsonSerializer.Serialize(this); } public byte[] GetBytes() diff --git a/src/Microservices/Common/ClassifiedAds.Infrastructure/ClassifiedAds.Infrastructure.csproj b/src/Microservices/Common/ClassifiedAds.Infrastructure/ClassifiedAds.Infrastructure.csproj index 7d9dabb70..fc01f225e 100644 --- a/src/Microservices/Common/ClassifiedAds.Infrastructure/ClassifiedAds.Infrastructure.csproj +++ b/src/Microservices/Common/ClassifiedAds.Infrastructure/ClassifiedAds.Infrastructure.csproj @@ -1,10 +1,10 @@  - - net6.0 - ClassifiedAds.Infrastructure - ClassifiedAds.Infrastructure.ruleset - + + net6.0 + ClassifiedAds.Infrastructure + ClassifiedAds.Infrastructure.ruleset + @@ -55,7 +55,6 @@ - @@ -80,19 +79,19 @@ - - - + + + + + + + PreserveNewest + libwkhtmltox.dll + + + PreserveNewest + libwkhtmltox.so + + - - - PreserveNewest - libwkhtmltox.dll - - - PreserveNewest - libwkhtmltox.so - - - diff --git a/src/Microservices/Common/ClassifiedAds.Infrastructure/Interceptors/ErrorCatchingInterceptor.cs b/src/Microservices/Common/ClassifiedAds.Infrastructure/Interceptors/ErrorCatchingInterceptor.cs index db197889a..aa0778b94 100644 --- a/src/Microservices/Common/ClassifiedAds.Infrastructure/Interceptors/ErrorCatchingInterceptor.cs +++ b/src/Microservices/Common/ClassifiedAds.Infrastructure/Interceptors/ErrorCatchingInterceptor.cs @@ -1,7 +1,8 @@ using Castle.DynamicProxy; using Microsoft.Extensions.Logging; -using Newtonsoft.Json; using System; +using System.Text.Json; +using System.Text.Json.Serialization; namespace ClassifiedAds.Infrastructure.Interceptors { @@ -27,7 +28,12 @@ public void Intercept(IInvocation invocation) var methodName = method.Name; // TODO: Ignore serialize large argument object. - var arguments = JsonConvert.SerializeObject(invocation.Arguments, Formatting.None, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); + var arguments = JsonSerializer.Serialize(invocation.Arguments, new JsonSerializerOptions() + { + WriteIndented = false, + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, + ReferenceHandler = ReferenceHandler.IgnoreCycles, + }); _logger.LogError($"An unhandled exception has occurred while executing the method: {className}.{methodName} with ({arguments}). {Environment.NewLine}{ex.ToString()}"); throw; } diff --git a/src/Microservices/Common/ClassifiedAds.Infrastructure/Interceptors/LoggingInterceptor.cs b/src/Microservices/Common/ClassifiedAds.Infrastructure/Interceptors/LoggingInterceptor.cs index e26bcf2bd..a28a1628a 100644 --- a/src/Microservices/Common/ClassifiedAds.Infrastructure/Interceptors/LoggingInterceptor.cs +++ b/src/Microservices/Common/ClassifiedAds.Infrastructure/Interceptors/LoggingInterceptor.cs @@ -1,7 +1,8 @@ using Castle.DynamicProxy; using Microsoft.Extensions.Logging; -using Newtonsoft.Json; using System.Diagnostics; +using System.Text.Json; +using System.Text.Json.Serialization; namespace ClassifiedAds.Infrastructure.Interceptors { @@ -19,7 +20,13 @@ public void Intercept(IInvocation invocation) var method = invocation.Method; var className = method.DeclaringType.Name; var methodName = method.Name; - var arguments = JsonConvert.SerializeObject(invocation.Arguments, Formatting.None, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); + + var arguments = JsonSerializer.Serialize(invocation.Arguments, new JsonSerializerOptions() + { + WriteIndented = false, + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, + ReferenceHandler = ReferenceHandler.IgnoreCycles, + }); _logger.LogDebug($"Start calling method: {className}.{methodName} with ({arguments})."); diff --git a/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventGrid/AzureEventGridSender.cs b/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventGrid/AzureEventGridSender.cs index 94fe52139..0b7cde3fd 100644 --- a/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventGrid/AzureEventGridSender.cs +++ b/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventGrid/AzureEventGridSender.cs @@ -1,9 +1,9 @@ using Azure; using Azure.Messaging.EventGrid; using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using System; using System.Collections.Generic; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -27,7 +27,7 @@ public async Task SendAsync(T message, MetaData metaData, CancellationToken canc EventGridPublisherClient client = new EventGridPublisherClient(new Uri(_domainEndpoint), new AzureKeyCredential(_domainKey)); - var data = new BinaryData(JsonConvert.SerializeObject(new Message + var data = new BinaryData(JsonSerializer.Serialize(new Message { Data = message, MetaData = metaData, diff --git a/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventHub/AzureEventHubReceiver.cs b/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventHub/AzureEventHubReceiver.cs index 415e620fa..b36db8c4d 100644 --- a/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventHub/AzureEventHubReceiver.cs +++ b/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventHub/AzureEventHubReceiver.cs @@ -3,9 +3,9 @@ using Azure.Messaging.EventHubs.Processor; using Azure.Storage.Blobs; using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using System; using System.Text; +using System.Text.Json; using System.Threading.Tasks; namespace ClassifiedAds.Infrastructure.MessageBrokers.AzureEventHub @@ -43,7 +43,7 @@ Task ProcessEventHandler(ProcessEventArgs eventArgs) try { var messageAsString = Encoding.UTF8.GetString(eventArgs.Data.EventBody); - var message = JsonConvert.DeserializeObject>(messageAsString); + var message = JsonSerializer.Deserialize>(messageAsString); action(message.Data, message.MetaData); } catch (Exception ex) diff --git a/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventHub/AzureEventHubSender.cs b/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventHub/AzureEventHubSender.cs index 9de932965..1d9961f56 100644 --- a/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventHub/AzureEventHubSender.cs +++ b/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventHub/AzureEventHubSender.cs @@ -1,8 +1,8 @@ using Azure.Messaging.EventHubs; using Azure.Messaging.EventHubs.Producer; using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using System.Collections.Generic; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -25,7 +25,7 @@ public async Task SendAsync(T message, MetaData metaData, CancellationToken canc var events = new List { - new EventData(JsonConvert.SerializeObject(new Message + new EventData(JsonSerializer.Serialize(new Message { Data = message, MetaData = metaData, diff --git a/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureQueue/AzureQueueReceiver.cs b/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureQueue/AzureQueueReceiver.cs index 8acab41b4..69bdf85b7 100644 --- a/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureQueue/AzureQueueReceiver.cs +++ b/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureQueue/AzureQueueReceiver.cs @@ -1,7 +1,7 @@ using Azure.Storage.Queues; using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using System; +using System.Text.Json; using System.Threading.Tasks; namespace ClassifiedAds.Infrastructure.MessageBrokers.AzureQueue @@ -28,7 +28,7 @@ private Task ReceiveAsync(Action action) { return ReceiveStringAsync(retrievedMessage => { - var message = JsonConvert.DeserializeObject>(retrievedMessage); + var message = JsonSerializer.Deserialize>(retrievedMessage); action(message.Data, message.MetaData); }); } diff --git a/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureQueue/AzureQueueSender.cs b/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureQueue/AzureQueueSender.cs index fb9c5dff6..1115ef6db 100644 --- a/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureQueue/AzureQueueSender.cs +++ b/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureQueue/AzureQueueSender.cs @@ -1,6 +1,6 @@ using Azure.Storage.Queues; using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -22,7 +22,7 @@ public async Task SendAsync(T message, MetaData metaData, CancellationToken canc var queueClient = new QueueClient(_connectionString, _queueName); await queueClient.CreateIfNotExistsAsync(cancellationToken: cancellationToken); - var jsonMessage = JsonConvert.SerializeObject(new Message + var jsonMessage = JsonSerializer.Serialize(new Message { Data = message, MetaData = metaData, diff --git a/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusReceiver.cs b/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusReceiver.cs index 1b75998d9..da4aaeebb 100644 --- a/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusReceiver.cs +++ b/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusReceiver.cs @@ -1,8 +1,8 @@ using Azure.Messaging.ServiceBus; using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using System; using System.Text; +using System.Text.Json; using System.Threading.Tasks; namespace ClassifiedAds.Infrastructure.MessageBrokers.AzureServiceBus @@ -27,7 +27,7 @@ private Task ReceiveAsync(Action action) { return ReceiveStringAsync(retrievedMessage => { - var message = JsonConvert.DeserializeObject>(retrievedMessage); + var message = JsonSerializer.Deserialize>(retrievedMessage); action(message.Data, message.MetaData); }); } diff --git a/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusSender.cs b/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusSender.cs index 7c309cfc7..1fc6881df 100644 --- a/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusSender.cs +++ b/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusSender.cs @@ -1,7 +1,7 @@ using Azure.Messaging.ServiceBus; using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using System.Text; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -22,7 +22,7 @@ public async Task SendAsync(T message, MetaData metaData, CancellationToken canc { await using var client = new ServiceBusClient(_connectionString); ServiceBusSender sender = client.CreateSender(_queueName); - var serviceBusMessage = new ServiceBusMessage(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new Message + var serviceBusMessage = new ServiceBusMessage(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(new Message { Data = message, MetaData = metaData, diff --git a/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusSubscriptionReceiver.cs b/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusSubscriptionReceiver.cs index 764912afe..15d9babbf 100644 --- a/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusSubscriptionReceiver.cs +++ b/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusSubscriptionReceiver.cs @@ -1,8 +1,8 @@ using Azure.Messaging.ServiceBus; using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using System; using System.Text; +using System.Text.Json; using System.Threading.Tasks; namespace ClassifiedAds.Infrastructure.MessageBrokers.AzureServiceBus @@ -29,7 +29,7 @@ private Task ReceiveAsync(Action action) { return ReceiveStringAsync(retrievedMessage => { - var message = JsonConvert.DeserializeObject>(retrievedMessage); + var message = JsonSerializer.Deserialize>(retrievedMessage); action(message.Data, message.MetaData); }); } diff --git a/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusTopicSender.cs b/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusTopicSender.cs index 940e24fa1..ed5aac057 100644 --- a/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusTopicSender.cs +++ b/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusTopicSender.cs @@ -1,7 +1,7 @@ using Azure.Messaging.ServiceBus; using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using System.Text; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -22,7 +22,7 @@ public async Task SendAsync(T message, MetaData metaData, CancellationToken canc { await using var client = new ServiceBusClient(_connectionString); ServiceBusSender sender = client.CreateSender(_topicName); - var serviceBusMessage = new ServiceBusMessage(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new Message + var serviceBusMessage = new ServiceBusMessage(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(new Message { Data = message, MetaData = metaData, diff --git a/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/Kafka/KafkaReceiver.cs b/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/Kafka/KafkaReceiver.cs index cdcc39073..15a9423cd 100644 --- a/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/Kafka/KafkaReceiver.cs +++ b/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/Kafka/KafkaReceiver.cs @@ -1,7 +1,7 @@ using ClassifiedAds.Domain.Infrastructure.MessageBrokers; using Confluent.Kafka; -using Newtonsoft.Json; using System; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -61,7 +61,7 @@ private void StartReceiving(Action action, CancellationToken cancel continue; } - var message = JsonConvert.DeserializeObject>(consumeResult.Message.Value); + var message = JsonSerializer.Deserialize>(consumeResult.Message.Value); action(message.Data, message.MetaData); } catch (ConsumeException e) diff --git a/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/Kafka/KafkaSender.cs b/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/Kafka/KafkaSender.cs index 788bb3f7f..710116178 100644 --- a/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/Kafka/KafkaSender.cs +++ b/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/Kafka/KafkaSender.cs @@ -1,7 +1,7 @@ using ClassifiedAds.Domain.Infrastructure.MessageBrokers; using Confluent.Kafka; -using Newtonsoft.Json; using System; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -30,7 +30,7 @@ public async Task SendAsync(T message, MetaData metaData, CancellationToken canc { _ = await _producer.ProduceAsync(_topic, new Message { - Value = JsonConvert.SerializeObject(new Message + Value = JsonSerializer.Serialize(new Message { Data = message, MetaData = metaData, diff --git a/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/RabbitMQ/RabbitMQReceiver.cs b/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/RabbitMQ/RabbitMQReceiver.cs index 82d1d01a2..9a63e5ba1 100644 --- a/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/RabbitMQ/RabbitMQReceiver.cs +++ b/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/RabbitMQ/RabbitMQReceiver.cs @@ -1,9 +1,9 @@ using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using RabbitMQ.Client; using RabbitMQ.Client.Events; using System; using System.Text; +using System.Text.Json; namespace ClassifiedAds.Infrastructure.MessageBrokers.RabbitMQ { @@ -56,7 +56,7 @@ This tells RabbitMQ not to give more than one message to a worker at a time. consumer.Received += (model, ea) => { var body = Encoding.UTF8.GetString(ea.Body.Span); - var message = JsonConvert.DeserializeObject>(body); + var message = JsonSerializer.Deserialize>(body); action(message.Data, message.MetaData); _channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false); }; diff --git a/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/RabbitMQ/RabbitMQSender.cs b/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/RabbitMQ/RabbitMQSender.cs index 202a5ed10..bb317941c 100644 --- a/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/RabbitMQ/RabbitMQSender.cs +++ b/src/Microservices/Common/ClassifiedAds.Infrastructure/MessageBrokers/RabbitMQ/RabbitMQSender.cs @@ -1,7 +1,7 @@ using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using RabbitMQ.Client; using System.Text; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -32,7 +32,7 @@ await Task.Run(() => { using var connection = _connectionFactory.CreateConnection(); using var channel = connection.CreateModel(); - var body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new Message + var body = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(new Message { Data = message, MetaData = metaData, diff --git a/src/Microservices/Services.Identity/ClassifiedAds.Services.Identity.AuthServer/Controllers/ApiResourceController.cs b/src/Microservices/Services.Identity/ClassifiedAds.Services.Identity.AuthServer/Controllers/ApiResourceController.cs index eb6c8e6c0..09cb4fac1 100644 --- a/src/Microservices/Services.Identity/ClassifiedAds.Services.Identity.AuthServer/Controllers/ApiResourceController.cs +++ b/src/Microservices/Services.Identity/ClassifiedAds.Services.Identity.AuthServer/Controllers/ApiResourceController.cs @@ -3,10 +3,10 @@ using IdentityServer4.EntityFramework.Entities; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json; namespace ClassifiedAds.IdentityServer.Controllers { @@ -62,7 +62,7 @@ public IActionResult Edit(ApiResourceModel model) if (!string.IsNullOrEmpty(model.UserClaimsItems)) { - var userClaims = JsonConvert.DeserializeObject>(model.UserClaimsItems); + var userClaims = JsonSerializer.Deserialize>(model.UserClaimsItems); api.UserClaims.AddRange(userClaims.Select(x => new ApiResourceClaim { diff --git a/src/Microservices/Services.Identity/ClassifiedAds.Services.Identity.AuthServer/Controllers/ApiScopeController.cs b/src/Microservices/Services.Identity/ClassifiedAds.Services.Identity.AuthServer/Controllers/ApiScopeController.cs index ef48b25fc..720454652 100644 --- a/src/Microservices/Services.Identity/ClassifiedAds.Services.Identity.AuthServer/Controllers/ApiScopeController.cs +++ b/src/Microservices/Services.Identity/ClassifiedAds.Services.Identity.AuthServer/Controllers/ApiScopeController.cs @@ -3,9 +3,9 @@ using IdentityServer4.EntityFramework.Entities; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Newtonsoft.Json; using System.Collections.Generic; using System.Linq; +using System.Text.Json; namespace ClassifiedAds.IdentityServer.Controllers { @@ -70,7 +70,7 @@ public IActionResult Edit(ApiScopeModel model) if (!string.IsNullOrEmpty(model.UserClaimsItems)) { - var userClaims = JsonConvert.DeserializeObject>(model.UserClaimsItems); + var userClaims = JsonSerializer.Deserialize>(model.UserClaimsItems); api.UserClaims.AddRange(userClaims.Select(x => new ApiScopeClaim { diff --git a/src/Microservices/Services.Identity/ClassifiedAds.Services.Identity.AuthServer/Controllers/IdentityResourceController.cs b/src/Microservices/Services.Identity/ClassifiedAds.Services.Identity.AuthServer/Controllers/IdentityResourceController.cs index f28df1877..443a89ca2 100644 --- a/src/Microservices/Services.Identity/ClassifiedAds.Services.Identity.AuthServer/Controllers/IdentityResourceController.cs +++ b/src/Microservices/Services.Identity/ClassifiedAds.Services.Identity.AuthServer/Controllers/IdentityResourceController.cs @@ -1,13 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using ClassifiedAds.IdentityServer.Models.IdentityResourceModels; +using ClassifiedAds.IdentityServer.Models.IdentityResourceModels; using IdentityServer4.EntityFramework.DbContexts; using IdentityServer4.EntityFramework.Entities; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Newtonsoft.Json; +using System.Collections.Generic; +using System.Linq; +using System.Text.Json; namespace ClassifiedAds.IdentityServer.Controllers { @@ -63,7 +61,7 @@ public IActionResult Edit(IdentityResourceModel model) if (!string.IsNullOrEmpty(model.UserClaimsItems)) { - model.UserClaims = JsonConvert.DeserializeObject>(model.UserClaimsItems); + model.UserClaims = JsonSerializer.Deserialize>(model.UserClaimsItems); identity.UserClaims.AddRange(model.UserClaims.Select(x => new IdentityResourceClaim { diff --git a/src/Microservices/Services.Identity/ClassifiedAds.Services.Identity.AuthServer/Models/ClientModels/ClientModel.cs b/src/Microservices/Services.Identity/ClassifiedAds.Services.Identity.AuthServer/Models/ClientModels/ClientModel.cs index bc4bf4b9a..722a6b5a3 100644 --- a/src/Microservices/Services.Identity/ClassifiedAds.Services.Identity.AuthServer/Models/ClientModels/ClientModel.cs +++ b/src/Microservices/Services.Identity/ClassifiedAds.Services.Identity.AuthServer/Models/ClientModels/ClientModel.cs @@ -2,9 +2,9 @@ using IdentityServer4.EntityFramework.Entities; using IdentityServer4.EntityFramework.Mappers; using IdentityServer4.Models; -using Newtonsoft.Json; using System.Collections.Generic; using System.Linq; +using System.Text.Json; namespace ClassifiedAds.IdentityServer.Models.ClientModels { @@ -82,7 +82,7 @@ private List ConvertItems(string items) { return string.IsNullOrWhiteSpace(items) ? new List() - : JsonConvert.DeserializeObject>(items); + : JsonSerializer.Deserialize>(items); } public void UpdateEntity(IdentityServer4.EntityFramework.Entities.Client entity) diff --git a/src/Microservices/Services.Identity/ClassifiedAds.Services.Identity.AuthServer/Quickstart/Diagnostics/DiagnosticsViewModel.cs b/src/Microservices/Services.Identity/ClassifiedAds.Services.Identity.AuthServer/Quickstart/Diagnostics/DiagnosticsViewModel.cs index f43c7685b..70b5c0578 100644 --- a/src/Microservices/Services.Identity/ClassifiedAds.Services.Identity.AuthServer/Quickstart/Diagnostics/DiagnosticsViewModel.cs +++ b/src/Microservices/Services.Identity/ClassifiedAds.Services.Identity.AuthServer/Quickstart/Diagnostics/DiagnosticsViewModel.cs @@ -4,9 +4,9 @@ using IdentityModel; using Microsoft.AspNetCore.Authentication; -using Newtonsoft.Json; using System.Collections.Generic; using System.Text; +using System.Text.Json; namespace IdentityServerHost.Quickstart.UI { @@ -22,7 +22,7 @@ public DiagnosticsViewModel(AuthenticateResult result) var bytes = Base64Url.Decode(encoded); var value = Encoding.UTF8.GetString(bytes); - Clients = JsonConvert.DeserializeObject(value); + Clients = JsonSerializer.Deserialize(value); } } diff --git a/src/Microservices/Services.Identity/ClassifiedAds.Services.Identity.AuthServer/TagHelpers/PickerTagHelper.cs b/src/Microservices/Services.Identity/ClassifiedAds.Services.Identity.AuthServer/TagHelpers/PickerTagHelper.cs index 2d7afaafb..086ee8e36 100644 --- a/src/Microservices/Services.Identity/ClassifiedAds.Services.Identity.AuthServer/TagHelpers/PickerTagHelper.cs +++ b/src/Microservices/Services.Identity/ClassifiedAds.Services.Identity.AuthServer/TagHelpers/PickerTagHelper.cs @@ -1,12 +1,9 @@ using Microsoft.AspNetCore.Html; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Razor.TagHelpers; -using Newtonsoft.Json; -using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Threading.Tasks; +using System.Text.Json; namespace ClassifiedAds.Services.Identity.AuthServer.TagHelpers { @@ -93,7 +90,7 @@ private void AddComponent(TagHelperOutput output) } }; - var rawPickerHtml = new HtmlString($"
"); + var rawPickerHtml = new HtmlString($"
"); output.Content.AppendHtml(rawPickerHtml); } diff --git a/src/Microservices/Services.Product/ClassifiedAds.Services.Product.Api/Controllers/ProductsController.cs b/src/Microservices/Services.Product/ClassifiedAds.Services.Product.Api/Controllers/ProductsController.cs index 517979e28..a073ddeb6 100644 --- a/src/Microservices/Services.Product/ClassifiedAds.Services.Product.Api/Controllers/ProductsController.cs +++ b/src/Microservices/Services.Product/ClassifiedAds.Services.Product.Api/Controllers/ProductsController.cs @@ -12,12 +12,12 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; -using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Mime; +using System.Text.Json; using System.Threading.Tasks; namespace ClassifiedAds.Services.Product.Controllers @@ -126,7 +126,7 @@ public async Task>> GetAuditLogs(Guid ProductModel previous = null; foreach (var log in logs.OrderBy(x => x.CreatedDateTime)) { - var data = JsonConvert.DeserializeObject(log.Log); + var data = JsonSerializer.Deserialize(log.Log); var highLight = new { Code = previous != null && data.Code != previous.Code, diff --git a/src/Microservices/Services.Storage/ClassifiedAds.Services.Storage.Api/Controllers/FilesController.cs b/src/Microservices/Services.Storage/ClassifiedAds.Services.Storage.Api/Controllers/FilesController.cs index 2f94537e9..cb2b46af0 100644 --- a/src/Microservices/Services.Storage/ClassifiedAds.Services.Storage.Api/Controllers/FilesController.cs +++ b/src/Microservices/Services.Storage/ClassifiedAds.Services.Storage.Api/Controllers/FilesController.cs @@ -11,7 +11,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; @@ -19,6 +18,7 @@ using System.Net; using System.Net.Mime; using System.Security.Cryptography; +using System.Text.Json; using System.Threading.Tasks; namespace ClassifiedAds.Services.Storage.Controllers @@ -166,7 +166,7 @@ public async Task>> GetAuditLogs(Guid FileEntry previous = null; foreach (var log in logs.OrderBy(x => x.CreatedDateTime)) { - var data = JsonConvert.DeserializeObject(log.Log); + var data = JsonSerializer.Deserialize(log.Log); var highLight = new { Name = previous != null && data.Name != previous.Name, diff --git a/src/ModularMonolith/ClassifiedAds.Application/Decorators/AuditLog/AuditLogCommandDecorator.cs b/src/ModularMonolith/ClassifiedAds.Application/Decorators/AuditLog/AuditLogCommandDecorator.cs index bc9090e36..91e47f012 100644 --- a/src/ModularMonolith/ClassifiedAds.Application/Decorators/AuditLog/AuditLogCommandDecorator.cs +++ b/src/ModularMonolith/ClassifiedAds.Application/Decorators/AuditLog/AuditLogCommandDecorator.cs @@ -1,7 +1,7 @@ using System; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; -using Newtonsoft.Json; namespace ClassifiedAds.Application.Decorators.AuditLog { @@ -18,7 +18,7 @@ public AuditLogCommandDecorator(ICommandHandler handler) public async Task HandleAsync(TCommand command, CancellationToken cancellationToken = default) { - var commandJson = JsonConvert.SerializeObject(command); + var commandJson = JsonSerializer.Serialize(command); Console.WriteLine($"Command of type {command.GetType().Name}: {commandJson}"); await _handler.HandleAsync(command, cancellationToken); } diff --git a/src/ModularMonolith/ClassifiedAds.Application/Decorators/AuditLog/AuditLogQueryDecorator.cs b/src/ModularMonolith/ClassifiedAds.Application/Decorators/AuditLog/AuditLogQueryDecorator.cs index 5f2b57d4c..554e10316 100644 --- a/src/ModularMonolith/ClassifiedAds.Application/Decorators/AuditLog/AuditLogQueryDecorator.cs +++ b/src/ModularMonolith/ClassifiedAds.Application/Decorators/AuditLog/AuditLogQueryDecorator.cs @@ -1,7 +1,7 @@ using System; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; -using Newtonsoft.Json; namespace ClassifiedAds.Application.Decorators.AuditLog { @@ -18,7 +18,7 @@ public AuditLogQueryDecorator(IQueryHandler handler) public Task HandleAsync(TQuery query, CancellationToken cancellationToken = default) { - string queryJson = JsonConvert.SerializeObject(query); + string queryJson = JsonSerializer.Serialize(query); Console.WriteLine($"Query of type {query.GetType().Name}: {queryJson}"); return _handler.HandleAsync(query, cancellationToken); } diff --git a/src/ModularMonolith/ClassifiedAds.CrossCuttingConcerns/ClassifiedAds.CrossCuttingConcerns.csproj b/src/ModularMonolith/ClassifiedAds.CrossCuttingConcerns/ClassifiedAds.CrossCuttingConcerns.csproj index 2abe3ca99..f9ae43c75 100644 --- a/src/ModularMonolith/ClassifiedAds.CrossCuttingConcerns/ClassifiedAds.CrossCuttingConcerns.csproj +++ b/src/ModularMonolith/ClassifiedAds.CrossCuttingConcerns/ClassifiedAds.CrossCuttingConcerns.csproj @@ -1,17 +1,17 @@  - - net6.0 - ClassifiedAds.CrossCuttingConcerns - ClassifiedAds.CrossCuttingConcerns.ruleset - + + net6.0 + ClassifiedAds.CrossCuttingConcerns + ClassifiedAds.CrossCuttingConcerns.ruleset + - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/src/ModularMonolith/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/CloningExtensions.cs b/src/ModularMonolith/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/CloningExtensions.cs index a67210374..4410be804 100644 --- a/src/ModularMonolith/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/CloningExtensions.cs +++ b/src/ModularMonolith/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/CloningExtensions.cs @@ -1,5 +1,5 @@ -using Newtonsoft.Json; -using System.Reflection; +using System.Reflection; +using System.Text.Json; namespace ClassifiedAds.CrossCuttingConcerns.ExtensionMethods { @@ -28,13 +28,7 @@ public static T DeepCloneJson(this T source) return default(T); } - // initialize inner objects individually - // for example in default constructor some list property initialized with some values, - // but in 'source' these items are cleaned - - // without ObjectCreationHandling.Replace default constructor values will be added to result - var deserializeSettings = new JsonSerializerSettings { ObjectCreationHandling = ObjectCreationHandling.Replace }; - - return JsonConvert.DeserializeObject(JsonConvert.SerializeObject(source), deserializeSettings); + return JsonSerializer.Deserialize(JsonSerializer.Serialize(source)); } } } diff --git a/src/ModularMonolith/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/HttpContentExtensions.cs b/src/ModularMonolith/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/HttpContentExtensions.cs index 2c7d3feb2..3b6b4c707 100644 --- a/src/ModularMonolith/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/HttpContentExtensions.cs +++ b/src/ModularMonolith/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/HttpContentExtensions.cs @@ -1,7 +1,6 @@ -using Newtonsoft.Json; -using System.IO; -using System.Net.Http; +using System.Net.Http; using System.Net.Http.Headers; +using System.Text.Json; using System.Threading.Tasks; namespace ClassifiedAds.CrossCuttingConcerns.ExtensionMethods @@ -10,19 +9,22 @@ public static class HttpContentExtensions { public static async Task ReadAs(this HttpContent httpContent) { - using (var streamReader = new StreamReader(await httpContent.ReadAsStreamAsync())) + var json = await httpContent.ReadAsStringAsync(); + + if (string.IsNullOrWhiteSpace(json)) { - using (var jsonTextReader = new JsonTextReader(streamReader)) - { - var jsonSerializer = new JsonSerializer(); - return jsonSerializer.Deserialize(jsonTextReader); - } + return default; } + + return JsonSerializer.Deserialize(json, new JsonSerializerOptions + { + PropertyNameCaseInsensitive = true, + }); } public static StringContent AsStringContent(this object obj, string contentType) { - var content = new StringContent(JsonConvert.SerializeObject(obj)); + var content = new StringContent(JsonSerializer.Serialize(obj)); content.Headers.ContentType = new MediaTypeHeaderValue(contentType); return content; } diff --git a/src/ModularMonolith/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/ObjectExtensions.cs b/src/ModularMonolith/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/ObjectExtensions.cs index 7edad2dc1..1f5888fa2 100644 --- a/src/ModularMonolith/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/ObjectExtensions.cs +++ b/src/ModularMonolith/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/ObjectExtensions.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json; +using System.Text.Json; namespace ClassifiedAds.CrossCuttingConcerns.ExtensionMethods { @@ -6,7 +6,7 @@ public static class ObjectExtensions { public static string AsJsonString(this object obj) { - var content = JsonConvert.SerializeObject(obj, Formatting.Indented); + var content = JsonSerializer.Serialize(obj, new JsonSerializerOptions { WriteIndented = true }); return content; } } diff --git a/src/ModularMonolith/ClassifiedAds.Domain/ClassifiedAds.Domain.csproj b/src/ModularMonolith/ClassifiedAds.Domain/ClassifiedAds.Domain.csproj index 907948686..36270ee4b 100644 --- a/src/ModularMonolith/ClassifiedAds.Domain/ClassifiedAds.Domain.csproj +++ b/src/ModularMonolith/ClassifiedAds.Domain/ClassifiedAds.Domain.csproj @@ -1,23 +1,23 @@  - - net6.0 - ClassifiedAds.Domain.ruleset - + + net6.0 + ClassifiedAds.Domain.ruleset + - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + - - - + + + diff --git a/src/ModularMonolith/ClassifiedAds.Domain/Infrastructure/MessageBrokers/Message.cs b/src/ModularMonolith/ClassifiedAds.Domain/Infrastructure/MessageBrokers/Message.cs index 544ce23c2..33f456c0c 100644 --- a/src/ModularMonolith/ClassifiedAds.Domain/Infrastructure/MessageBrokers/Message.cs +++ b/src/ModularMonolith/ClassifiedAds.Domain/Infrastructure/MessageBrokers/Message.cs @@ -1,5 +1,5 @@ -using Newtonsoft.Json; -using System.Text; +using System.Text; +using System.Text.Json; namespace ClassifiedAds.Domain.Infrastructure.MessageBrokers { @@ -11,7 +11,7 @@ public class Message public string SerializeObject() { - return JsonConvert.SerializeObject(this); + return JsonSerializer.Serialize(this); } public byte[] GetBytes() diff --git a/src/ModularMonolith/ClassifiedAds.IdentityServer/Controllers/ApiResourceController.cs b/src/ModularMonolith/ClassifiedAds.IdentityServer/Controllers/ApiResourceController.cs index eb6c8e6c0..09cb4fac1 100644 --- a/src/ModularMonolith/ClassifiedAds.IdentityServer/Controllers/ApiResourceController.cs +++ b/src/ModularMonolith/ClassifiedAds.IdentityServer/Controllers/ApiResourceController.cs @@ -3,10 +3,10 @@ using IdentityServer4.EntityFramework.Entities; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json; namespace ClassifiedAds.IdentityServer.Controllers { @@ -62,7 +62,7 @@ public IActionResult Edit(ApiResourceModel model) if (!string.IsNullOrEmpty(model.UserClaimsItems)) { - var userClaims = JsonConvert.DeserializeObject>(model.UserClaimsItems); + var userClaims = JsonSerializer.Deserialize>(model.UserClaimsItems); api.UserClaims.AddRange(userClaims.Select(x => new ApiResourceClaim { diff --git a/src/ModularMonolith/ClassifiedAds.IdentityServer/Controllers/ApiScopeController.cs b/src/ModularMonolith/ClassifiedAds.IdentityServer/Controllers/ApiScopeController.cs index ef48b25fc..720454652 100644 --- a/src/ModularMonolith/ClassifiedAds.IdentityServer/Controllers/ApiScopeController.cs +++ b/src/ModularMonolith/ClassifiedAds.IdentityServer/Controllers/ApiScopeController.cs @@ -3,9 +3,9 @@ using IdentityServer4.EntityFramework.Entities; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Newtonsoft.Json; using System.Collections.Generic; using System.Linq; +using System.Text.Json; namespace ClassifiedAds.IdentityServer.Controllers { @@ -70,7 +70,7 @@ public IActionResult Edit(ApiScopeModel model) if (!string.IsNullOrEmpty(model.UserClaimsItems)) { - var userClaims = JsonConvert.DeserializeObject>(model.UserClaimsItems); + var userClaims = JsonSerializer.Deserialize>(model.UserClaimsItems); api.UserClaims.AddRange(userClaims.Select(x => new ApiScopeClaim { diff --git a/src/ModularMonolith/ClassifiedAds.IdentityServer/Controllers/IdentityResourceController.cs b/src/ModularMonolith/ClassifiedAds.IdentityServer/Controllers/IdentityResourceController.cs index f28df1877..443a89ca2 100644 --- a/src/ModularMonolith/ClassifiedAds.IdentityServer/Controllers/IdentityResourceController.cs +++ b/src/ModularMonolith/ClassifiedAds.IdentityServer/Controllers/IdentityResourceController.cs @@ -1,13 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using ClassifiedAds.IdentityServer.Models.IdentityResourceModels; +using ClassifiedAds.IdentityServer.Models.IdentityResourceModels; using IdentityServer4.EntityFramework.DbContexts; using IdentityServer4.EntityFramework.Entities; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Newtonsoft.Json; +using System.Collections.Generic; +using System.Linq; +using System.Text.Json; namespace ClassifiedAds.IdentityServer.Controllers { @@ -63,7 +61,7 @@ public IActionResult Edit(IdentityResourceModel model) if (!string.IsNullOrEmpty(model.UserClaimsItems)) { - model.UserClaims = JsonConvert.DeserializeObject>(model.UserClaimsItems); + model.UserClaims = JsonSerializer.Deserialize>(model.UserClaimsItems); identity.UserClaims.AddRange(model.UserClaims.Select(x => new IdentityResourceClaim { diff --git a/src/ModularMonolith/ClassifiedAds.IdentityServer/Models/ClientModels/ClientModel.cs b/src/ModularMonolith/ClassifiedAds.IdentityServer/Models/ClientModels/ClientModel.cs index bc4bf4b9a..722a6b5a3 100644 --- a/src/ModularMonolith/ClassifiedAds.IdentityServer/Models/ClientModels/ClientModel.cs +++ b/src/ModularMonolith/ClassifiedAds.IdentityServer/Models/ClientModels/ClientModel.cs @@ -2,9 +2,9 @@ using IdentityServer4.EntityFramework.Entities; using IdentityServer4.EntityFramework.Mappers; using IdentityServer4.Models; -using Newtonsoft.Json; using System.Collections.Generic; using System.Linq; +using System.Text.Json; namespace ClassifiedAds.IdentityServer.Models.ClientModels { @@ -82,7 +82,7 @@ private List ConvertItems(string items) { return string.IsNullOrWhiteSpace(items) ? new List() - : JsonConvert.DeserializeObject>(items); + : JsonSerializer.Deserialize>(items); } public void UpdateEntity(IdentityServer4.EntityFramework.Entities.Client entity) diff --git a/src/ModularMonolith/ClassifiedAds.IdentityServer/Quickstart/Diagnostics/DiagnosticsViewModel.cs b/src/ModularMonolith/ClassifiedAds.IdentityServer/Quickstart/Diagnostics/DiagnosticsViewModel.cs index f43c7685b..70b5c0578 100644 --- a/src/ModularMonolith/ClassifiedAds.IdentityServer/Quickstart/Diagnostics/DiagnosticsViewModel.cs +++ b/src/ModularMonolith/ClassifiedAds.IdentityServer/Quickstart/Diagnostics/DiagnosticsViewModel.cs @@ -4,9 +4,9 @@ using IdentityModel; using Microsoft.AspNetCore.Authentication; -using Newtonsoft.Json; using System.Collections.Generic; using System.Text; +using System.Text.Json; namespace IdentityServerHost.Quickstart.UI { @@ -22,7 +22,7 @@ public DiagnosticsViewModel(AuthenticateResult result) var bytes = Base64Url.Decode(encoded); var value = Encoding.UTF8.GetString(bytes); - Clients = JsonConvert.DeserializeObject(value); + Clients = JsonSerializer.Deserialize(value); } } diff --git a/src/ModularMonolith/ClassifiedAds.IdentityServer/TagHelpers/PickerTagHelper.cs b/src/ModularMonolith/ClassifiedAds.IdentityServer/TagHelpers/PickerTagHelper.cs index 9e95c8558..79a0147c1 100644 --- a/src/ModularMonolith/ClassifiedAds.IdentityServer/TagHelpers/PickerTagHelper.cs +++ b/src/ModularMonolith/ClassifiedAds.IdentityServer/TagHelpers/PickerTagHelper.cs @@ -1,12 +1,9 @@ using Microsoft.AspNetCore.Html; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Razor.TagHelpers; -using Newtonsoft.Json; -using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Threading.Tasks; +using System.Text.Json; namespace ClassifiedAds.IdentityServer.TagHelpers { @@ -93,7 +90,7 @@ private void AddComponent(TagHelperOutput output) } }; - var rawPickerHtml = new HtmlString($"
"); + var rawPickerHtml = new HtmlString($"
"); output.Content.AppendHtml(rawPickerHtml); } diff --git a/src/ModularMonolith/ClassifiedAds.Infrastructure/ClassifiedAds.Infrastructure.csproj b/src/ModularMonolith/ClassifiedAds.Infrastructure/ClassifiedAds.Infrastructure.csproj index 797eb75a0..126f2c06f 100644 --- a/src/ModularMonolith/ClassifiedAds.Infrastructure/ClassifiedAds.Infrastructure.csproj +++ b/src/ModularMonolith/ClassifiedAds.Infrastructure/ClassifiedAds.Infrastructure.csproj @@ -53,7 +53,6 @@ - diff --git a/src/ModularMonolith/ClassifiedAds.Infrastructure/Interceptors/ErrorCatchingInterceptor.cs b/src/ModularMonolith/ClassifiedAds.Infrastructure/Interceptors/ErrorCatchingInterceptor.cs index db197889a..aa0778b94 100644 --- a/src/ModularMonolith/ClassifiedAds.Infrastructure/Interceptors/ErrorCatchingInterceptor.cs +++ b/src/ModularMonolith/ClassifiedAds.Infrastructure/Interceptors/ErrorCatchingInterceptor.cs @@ -1,7 +1,8 @@ using Castle.DynamicProxy; using Microsoft.Extensions.Logging; -using Newtonsoft.Json; using System; +using System.Text.Json; +using System.Text.Json.Serialization; namespace ClassifiedAds.Infrastructure.Interceptors { @@ -27,7 +28,12 @@ public void Intercept(IInvocation invocation) var methodName = method.Name; // TODO: Ignore serialize large argument object. - var arguments = JsonConvert.SerializeObject(invocation.Arguments, Formatting.None, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); + var arguments = JsonSerializer.Serialize(invocation.Arguments, new JsonSerializerOptions() + { + WriteIndented = false, + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, + ReferenceHandler = ReferenceHandler.IgnoreCycles, + }); _logger.LogError($"An unhandled exception has occurred while executing the method: {className}.{methodName} with ({arguments}). {Environment.NewLine}{ex.ToString()}"); throw; } diff --git a/src/ModularMonolith/ClassifiedAds.Infrastructure/Interceptors/LoggingInterceptor.cs b/src/ModularMonolith/ClassifiedAds.Infrastructure/Interceptors/LoggingInterceptor.cs index e26bcf2bd..a28a1628a 100644 --- a/src/ModularMonolith/ClassifiedAds.Infrastructure/Interceptors/LoggingInterceptor.cs +++ b/src/ModularMonolith/ClassifiedAds.Infrastructure/Interceptors/LoggingInterceptor.cs @@ -1,7 +1,8 @@ using Castle.DynamicProxy; using Microsoft.Extensions.Logging; -using Newtonsoft.Json; using System.Diagnostics; +using System.Text.Json; +using System.Text.Json.Serialization; namespace ClassifiedAds.Infrastructure.Interceptors { @@ -19,7 +20,13 @@ public void Intercept(IInvocation invocation) var method = invocation.Method; var className = method.DeclaringType.Name; var methodName = method.Name; - var arguments = JsonConvert.SerializeObject(invocation.Arguments, Formatting.None, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); + + var arguments = JsonSerializer.Serialize(invocation.Arguments, new JsonSerializerOptions() + { + WriteIndented = false, + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, + ReferenceHandler = ReferenceHandler.IgnoreCycles, + }); _logger.LogDebug($"Start calling method: {className}.{methodName} with ({arguments})."); diff --git a/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventGrid/AzureEventGridSender.cs b/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventGrid/AzureEventGridSender.cs index 94fe52139..0b7cde3fd 100644 --- a/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventGrid/AzureEventGridSender.cs +++ b/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventGrid/AzureEventGridSender.cs @@ -1,9 +1,9 @@ using Azure; using Azure.Messaging.EventGrid; using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using System; using System.Collections.Generic; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -27,7 +27,7 @@ public async Task SendAsync(T message, MetaData metaData, CancellationToken canc EventGridPublisherClient client = new EventGridPublisherClient(new Uri(_domainEndpoint), new AzureKeyCredential(_domainKey)); - var data = new BinaryData(JsonConvert.SerializeObject(new Message + var data = new BinaryData(JsonSerializer.Serialize(new Message { Data = message, MetaData = metaData, diff --git a/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventHub/AzureEventHubReceiver.cs b/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventHub/AzureEventHubReceiver.cs index 415e620fa..b36db8c4d 100644 --- a/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventHub/AzureEventHubReceiver.cs +++ b/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventHub/AzureEventHubReceiver.cs @@ -3,9 +3,9 @@ using Azure.Messaging.EventHubs.Processor; using Azure.Storage.Blobs; using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using System; using System.Text; +using System.Text.Json; using System.Threading.Tasks; namespace ClassifiedAds.Infrastructure.MessageBrokers.AzureEventHub @@ -43,7 +43,7 @@ Task ProcessEventHandler(ProcessEventArgs eventArgs) try { var messageAsString = Encoding.UTF8.GetString(eventArgs.Data.EventBody); - var message = JsonConvert.DeserializeObject>(messageAsString); + var message = JsonSerializer.Deserialize>(messageAsString); action(message.Data, message.MetaData); } catch (Exception ex) diff --git a/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventHub/AzureEventHubSender.cs b/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventHub/AzureEventHubSender.cs index 9de932965..1d9961f56 100644 --- a/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventHub/AzureEventHubSender.cs +++ b/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventHub/AzureEventHubSender.cs @@ -1,8 +1,8 @@ using Azure.Messaging.EventHubs; using Azure.Messaging.EventHubs.Producer; using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using System.Collections.Generic; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -25,7 +25,7 @@ public async Task SendAsync(T message, MetaData metaData, CancellationToken canc var events = new List { - new EventData(JsonConvert.SerializeObject(new Message + new EventData(JsonSerializer.Serialize(new Message { Data = message, MetaData = metaData, diff --git a/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureQueue/AzureQueueReceiver.cs b/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureQueue/AzureQueueReceiver.cs index 8acab41b4..69bdf85b7 100644 --- a/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureQueue/AzureQueueReceiver.cs +++ b/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureQueue/AzureQueueReceiver.cs @@ -1,7 +1,7 @@ using Azure.Storage.Queues; using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using System; +using System.Text.Json; using System.Threading.Tasks; namespace ClassifiedAds.Infrastructure.MessageBrokers.AzureQueue @@ -28,7 +28,7 @@ private Task ReceiveAsync(Action action) { return ReceiveStringAsync(retrievedMessage => { - var message = JsonConvert.DeserializeObject>(retrievedMessage); + var message = JsonSerializer.Deserialize>(retrievedMessage); action(message.Data, message.MetaData); }); } diff --git a/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureQueue/AzureQueueSender.cs b/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureQueue/AzureQueueSender.cs index fb9c5dff6..1115ef6db 100644 --- a/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureQueue/AzureQueueSender.cs +++ b/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureQueue/AzureQueueSender.cs @@ -1,6 +1,6 @@ using Azure.Storage.Queues; using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -22,7 +22,7 @@ public async Task SendAsync(T message, MetaData metaData, CancellationToken canc var queueClient = new QueueClient(_connectionString, _queueName); await queueClient.CreateIfNotExistsAsync(cancellationToken: cancellationToken); - var jsonMessage = JsonConvert.SerializeObject(new Message + var jsonMessage = JsonSerializer.Serialize(new Message { Data = message, MetaData = metaData, diff --git a/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusReceiver.cs b/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusReceiver.cs index 1b75998d9..da4aaeebb 100644 --- a/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusReceiver.cs +++ b/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusReceiver.cs @@ -1,8 +1,8 @@ using Azure.Messaging.ServiceBus; using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using System; using System.Text; +using System.Text.Json; using System.Threading.Tasks; namespace ClassifiedAds.Infrastructure.MessageBrokers.AzureServiceBus @@ -27,7 +27,7 @@ private Task ReceiveAsync(Action action) { return ReceiveStringAsync(retrievedMessage => { - var message = JsonConvert.DeserializeObject>(retrievedMessage); + var message = JsonSerializer.Deserialize>(retrievedMessage); action(message.Data, message.MetaData); }); } diff --git a/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusSender.cs b/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusSender.cs index 7c309cfc7..1fc6881df 100644 --- a/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusSender.cs +++ b/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusSender.cs @@ -1,7 +1,7 @@ using Azure.Messaging.ServiceBus; using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using System.Text; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -22,7 +22,7 @@ public async Task SendAsync(T message, MetaData metaData, CancellationToken canc { await using var client = new ServiceBusClient(_connectionString); ServiceBusSender sender = client.CreateSender(_queueName); - var serviceBusMessage = new ServiceBusMessage(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new Message + var serviceBusMessage = new ServiceBusMessage(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(new Message { Data = message, MetaData = metaData, diff --git a/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusSubscriptionReceiver.cs b/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusSubscriptionReceiver.cs index 764912afe..15d9babbf 100644 --- a/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusSubscriptionReceiver.cs +++ b/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusSubscriptionReceiver.cs @@ -1,8 +1,8 @@ using Azure.Messaging.ServiceBus; using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using System; using System.Text; +using System.Text.Json; using System.Threading.Tasks; namespace ClassifiedAds.Infrastructure.MessageBrokers.AzureServiceBus @@ -29,7 +29,7 @@ private Task ReceiveAsync(Action action) { return ReceiveStringAsync(retrievedMessage => { - var message = JsonConvert.DeserializeObject>(retrievedMessage); + var message = JsonSerializer.Deserialize>(retrievedMessage); action(message.Data, message.MetaData); }); } diff --git a/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusTopicSender.cs b/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusTopicSender.cs index 940e24fa1..ed5aac057 100644 --- a/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusTopicSender.cs +++ b/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusTopicSender.cs @@ -1,7 +1,7 @@ using Azure.Messaging.ServiceBus; using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using System.Text; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -22,7 +22,7 @@ public async Task SendAsync(T message, MetaData metaData, CancellationToken canc { await using var client = new ServiceBusClient(_connectionString); ServiceBusSender sender = client.CreateSender(_topicName); - var serviceBusMessage = new ServiceBusMessage(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new Message + var serviceBusMessage = new ServiceBusMessage(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(new Message { Data = message, MetaData = metaData, diff --git a/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/Kafka/KafkaReceiver.cs b/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/Kafka/KafkaReceiver.cs index cdcc39073..15a9423cd 100644 --- a/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/Kafka/KafkaReceiver.cs +++ b/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/Kafka/KafkaReceiver.cs @@ -1,7 +1,7 @@ using ClassifiedAds.Domain.Infrastructure.MessageBrokers; using Confluent.Kafka; -using Newtonsoft.Json; using System; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -61,7 +61,7 @@ private void StartReceiving(Action action, CancellationToken cancel continue; } - var message = JsonConvert.DeserializeObject>(consumeResult.Message.Value); + var message = JsonSerializer.Deserialize>(consumeResult.Message.Value); action(message.Data, message.MetaData); } catch (ConsumeException e) diff --git a/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/Kafka/KafkaSender.cs b/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/Kafka/KafkaSender.cs index 788bb3f7f..710116178 100644 --- a/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/Kafka/KafkaSender.cs +++ b/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/Kafka/KafkaSender.cs @@ -1,7 +1,7 @@ using ClassifiedAds.Domain.Infrastructure.MessageBrokers; using Confluent.Kafka; -using Newtonsoft.Json; using System; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -30,7 +30,7 @@ public async Task SendAsync(T message, MetaData metaData, CancellationToken canc { _ = await _producer.ProduceAsync(_topic, new Message { - Value = JsonConvert.SerializeObject(new Message + Value = JsonSerializer.Serialize(new Message { Data = message, MetaData = metaData, diff --git a/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/RabbitMQ/RabbitMQReceiver.cs b/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/RabbitMQ/RabbitMQReceiver.cs index 82d1d01a2..9a63e5ba1 100644 --- a/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/RabbitMQ/RabbitMQReceiver.cs +++ b/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/RabbitMQ/RabbitMQReceiver.cs @@ -1,9 +1,9 @@ using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using RabbitMQ.Client; using RabbitMQ.Client.Events; using System; using System.Text; +using System.Text.Json; namespace ClassifiedAds.Infrastructure.MessageBrokers.RabbitMQ { @@ -56,7 +56,7 @@ This tells RabbitMQ not to give more than one message to a worker at a time. consumer.Received += (model, ea) => { var body = Encoding.UTF8.GetString(ea.Body.Span); - var message = JsonConvert.DeserializeObject>(body); + var message = JsonSerializer.Deserialize>(body); action(message.Data, message.MetaData); _channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false); }; diff --git a/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/RabbitMQ/RabbitMQSender.cs b/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/RabbitMQ/RabbitMQSender.cs index 202a5ed10..bb317941c 100644 --- a/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/RabbitMQ/RabbitMQSender.cs +++ b/src/ModularMonolith/ClassifiedAds.Infrastructure/MessageBrokers/RabbitMQ/RabbitMQSender.cs @@ -1,7 +1,7 @@ using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using RabbitMQ.Client; using System.Text; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -32,7 +32,7 @@ await Task.Run(() => { using var connection = _connectionFactory.CreateConnection(); using var channel = connection.CreateModel(); - var body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new Message + var body = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(new Message { Data = message, MetaData = metaData, diff --git a/src/ModularMonolith/ClassifiedAds.Modules.Product/Controllers/ProductsController.cs b/src/ModularMonolith/ClassifiedAds.Modules.Product/Controllers/ProductsController.cs index 672850bf1..c7c8200a5 100644 --- a/src/ModularMonolith/ClassifiedAds.Modules.Product/Controllers/ProductsController.cs +++ b/src/ModularMonolith/ClassifiedAds.Modules.Product/Controllers/ProductsController.cs @@ -12,12 +12,12 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; -using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Mime; +using System.Text.Json; using System.Threading.Tasks; namespace ClassifiedAds.Modules.Product.Controllers @@ -126,7 +126,7 @@ public async Task>> GetAuditLogs(Guid ProductModel previous = null; foreach (var log in logs.OrderBy(x => x.CreatedDateTime)) { - var data = JsonConvert.DeserializeObject(log.Log); + var data = JsonSerializer.Deserialize(log.Log); var highLight = new { Code = previous != null && data.Code != previous.Code, diff --git a/src/ModularMonolith/ClassifiedAds.Modules.Storage/Controllers/FilesController.cs b/src/ModularMonolith/ClassifiedAds.Modules.Storage/Controllers/FilesController.cs index d476142c0..9b98ac4b9 100644 --- a/src/ModularMonolith/ClassifiedAds.Modules.Storage/Controllers/FilesController.cs +++ b/src/ModularMonolith/ClassifiedAds.Modules.Storage/Controllers/FilesController.cs @@ -11,7 +11,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; @@ -19,6 +18,7 @@ using System.Net; using System.Net.Mime; using System.Security.Cryptography; +using System.Text.Json; using System.Threading.Tasks; namespace ClassifiedAds.Modules.Storage.Controllers @@ -166,7 +166,7 @@ public async Task>> GetAuditLogs(Guid FileEntry previous = null; foreach (var log in logs.OrderBy(x => x.CreatedDateTime)) { - var data = JsonConvert.DeserializeObject(log.Log); + var data = JsonSerializer.Deserialize(log.Log); var highLight = new { Name = previous != null && data.Name != previous.Name, diff --git a/src/Monolith/ClassifiedAds.Application/Decorators/AuditLog/AuditLogCommandDecorator.cs b/src/Monolith/ClassifiedAds.Application/Decorators/AuditLog/AuditLogCommandDecorator.cs index bc9090e36..91e47f012 100644 --- a/src/Monolith/ClassifiedAds.Application/Decorators/AuditLog/AuditLogCommandDecorator.cs +++ b/src/Monolith/ClassifiedAds.Application/Decorators/AuditLog/AuditLogCommandDecorator.cs @@ -1,7 +1,7 @@ using System; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; -using Newtonsoft.Json; namespace ClassifiedAds.Application.Decorators.AuditLog { @@ -18,7 +18,7 @@ public AuditLogCommandDecorator(ICommandHandler handler) public async Task HandleAsync(TCommand command, CancellationToken cancellationToken = default) { - var commandJson = JsonConvert.SerializeObject(command); + var commandJson = JsonSerializer.Serialize(command); Console.WriteLine($"Command of type {command.GetType().Name}: {commandJson}"); await _handler.HandleAsync(command, cancellationToken); } diff --git a/src/Monolith/ClassifiedAds.Application/Decorators/AuditLog/AuditLogQueryDecorator.cs b/src/Monolith/ClassifiedAds.Application/Decorators/AuditLog/AuditLogQueryDecorator.cs index 5f2b57d4c..554e10316 100644 --- a/src/Monolith/ClassifiedAds.Application/Decorators/AuditLog/AuditLogQueryDecorator.cs +++ b/src/Monolith/ClassifiedAds.Application/Decorators/AuditLog/AuditLogQueryDecorator.cs @@ -1,7 +1,7 @@ using System; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; -using Newtonsoft.Json; namespace ClassifiedAds.Application.Decorators.AuditLog { @@ -18,7 +18,7 @@ public AuditLogQueryDecorator(IQueryHandler handler) public Task HandleAsync(TQuery query, CancellationToken cancellationToken = default) { - string queryJson = JsonConvert.SerializeObject(query); + string queryJson = JsonSerializer.Serialize(query); Console.WriteLine($"Query of type {query.GetType().Name}: {queryJson}"); return _handler.HandleAsync(query, cancellationToken); } diff --git a/src/Monolith/ClassifiedAds.CrossCuttingConcerns/ClassifiedAds.CrossCuttingConcerns.csproj b/src/Monolith/ClassifiedAds.CrossCuttingConcerns/ClassifiedAds.CrossCuttingConcerns.csproj index b6567afbd..483048335 100644 --- a/src/Monolith/ClassifiedAds.CrossCuttingConcerns/ClassifiedAds.CrossCuttingConcerns.csproj +++ b/src/Monolith/ClassifiedAds.CrossCuttingConcerns/ClassifiedAds.CrossCuttingConcerns.csproj @@ -7,11 +7,11 @@ - all runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/src/Monolith/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/CloningExtensions.cs b/src/Monolith/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/CloningExtensions.cs index a67210374..4410be804 100644 --- a/src/Monolith/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/CloningExtensions.cs +++ b/src/Monolith/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/CloningExtensions.cs @@ -1,5 +1,5 @@ -using Newtonsoft.Json; -using System.Reflection; +using System.Reflection; +using System.Text.Json; namespace ClassifiedAds.CrossCuttingConcerns.ExtensionMethods { @@ -28,13 +28,7 @@ public static T DeepCloneJson(this T source) return default(T); } - // initialize inner objects individually - // for example in default constructor some list property initialized with some values, - // but in 'source' these items are cleaned - - // without ObjectCreationHandling.Replace default constructor values will be added to result - var deserializeSettings = new JsonSerializerSettings { ObjectCreationHandling = ObjectCreationHandling.Replace }; - - return JsonConvert.DeserializeObject(JsonConvert.SerializeObject(source), deserializeSettings); + return JsonSerializer.Deserialize(JsonSerializer.Serialize(source)); } } } diff --git a/src/Monolith/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/HttpContentExtensions.cs b/src/Monolith/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/HttpContentExtensions.cs index 2c7d3feb2..3b6b4c707 100644 --- a/src/Monolith/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/HttpContentExtensions.cs +++ b/src/Monolith/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/HttpContentExtensions.cs @@ -1,7 +1,6 @@ -using Newtonsoft.Json; -using System.IO; -using System.Net.Http; +using System.Net.Http; using System.Net.Http.Headers; +using System.Text.Json; using System.Threading.Tasks; namespace ClassifiedAds.CrossCuttingConcerns.ExtensionMethods @@ -10,19 +9,22 @@ public static class HttpContentExtensions { public static async Task ReadAs(this HttpContent httpContent) { - using (var streamReader = new StreamReader(await httpContent.ReadAsStreamAsync())) + var json = await httpContent.ReadAsStringAsync(); + + if (string.IsNullOrWhiteSpace(json)) { - using (var jsonTextReader = new JsonTextReader(streamReader)) - { - var jsonSerializer = new JsonSerializer(); - return jsonSerializer.Deserialize(jsonTextReader); - } + return default; } + + return JsonSerializer.Deserialize(json, new JsonSerializerOptions + { + PropertyNameCaseInsensitive = true, + }); } public static StringContent AsStringContent(this object obj, string contentType) { - var content = new StringContent(JsonConvert.SerializeObject(obj)); + var content = new StringContent(JsonSerializer.Serialize(obj)); content.Headers.ContentType = new MediaTypeHeaderValue(contentType); return content; } diff --git a/src/Monolith/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/ObjectExtensions.cs b/src/Monolith/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/ObjectExtensions.cs index 7edad2dc1..1f5888fa2 100644 --- a/src/Monolith/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/ObjectExtensions.cs +++ b/src/Monolith/ClassifiedAds.CrossCuttingConcerns/ExtensionMethods/ObjectExtensions.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json; +using System.Text.Json; namespace ClassifiedAds.CrossCuttingConcerns.ExtensionMethods { @@ -6,7 +6,7 @@ public static class ObjectExtensions { public static string AsJsonString(this object obj) { - var content = JsonConvert.SerializeObject(obj, Formatting.Indented); + var content = JsonSerializer.Serialize(obj, new JsonSerializerOptions { WriteIndented = true }); return content; } } diff --git a/src/Monolith/ClassifiedAds.Domain/ClassifiedAds.Domain.csproj b/src/Monolith/ClassifiedAds.Domain/ClassifiedAds.Domain.csproj index 907948686..36270ee4b 100644 --- a/src/Monolith/ClassifiedAds.Domain/ClassifiedAds.Domain.csproj +++ b/src/Monolith/ClassifiedAds.Domain/ClassifiedAds.Domain.csproj @@ -1,23 +1,23 @@  - - net6.0 - ClassifiedAds.Domain.ruleset - + + net6.0 + ClassifiedAds.Domain.ruleset + - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + - - - + + + diff --git a/src/Monolith/ClassifiedAds.Domain/Infrastructure/MessageBrokers/Message.cs b/src/Monolith/ClassifiedAds.Domain/Infrastructure/MessageBrokers/Message.cs index 544ce23c2..33f456c0c 100644 --- a/src/Monolith/ClassifiedAds.Domain/Infrastructure/MessageBrokers/Message.cs +++ b/src/Monolith/ClassifiedAds.Domain/Infrastructure/MessageBrokers/Message.cs @@ -1,5 +1,5 @@ -using Newtonsoft.Json; -using System.Text; +using System.Text; +using System.Text.Json; namespace ClassifiedAds.Domain.Infrastructure.MessageBrokers { @@ -11,7 +11,7 @@ public class Message public string SerializeObject() { - return JsonConvert.SerializeObject(this); + return JsonSerializer.Serialize(this); } public byte[] GetBytes() diff --git a/src/Monolith/ClassifiedAds.IdentityServer/Controllers/ApiResourceController.cs b/src/Monolith/ClassifiedAds.IdentityServer/Controllers/ApiResourceController.cs index eb6c8e6c0..09cb4fac1 100644 --- a/src/Monolith/ClassifiedAds.IdentityServer/Controllers/ApiResourceController.cs +++ b/src/Monolith/ClassifiedAds.IdentityServer/Controllers/ApiResourceController.cs @@ -3,10 +3,10 @@ using IdentityServer4.EntityFramework.Entities; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json; namespace ClassifiedAds.IdentityServer.Controllers { @@ -62,7 +62,7 @@ public IActionResult Edit(ApiResourceModel model) if (!string.IsNullOrEmpty(model.UserClaimsItems)) { - var userClaims = JsonConvert.DeserializeObject>(model.UserClaimsItems); + var userClaims = JsonSerializer.Deserialize>(model.UserClaimsItems); api.UserClaims.AddRange(userClaims.Select(x => new ApiResourceClaim { diff --git a/src/Monolith/ClassifiedAds.IdentityServer/Controllers/ApiScopeController.cs b/src/Monolith/ClassifiedAds.IdentityServer/Controllers/ApiScopeController.cs index ef48b25fc..720454652 100644 --- a/src/Monolith/ClassifiedAds.IdentityServer/Controllers/ApiScopeController.cs +++ b/src/Monolith/ClassifiedAds.IdentityServer/Controllers/ApiScopeController.cs @@ -3,9 +3,9 @@ using IdentityServer4.EntityFramework.Entities; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Newtonsoft.Json; using System.Collections.Generic; using System.Linq; +using System.Text.Json; namespace ClassifiedAds.IdentityServer.Controllers { @@ -70,7 +70,7 @@ public IActionResult Edit(ApiScopeModel model) if (!string.IsNullOrEmpty(model.UserClaimsItems)) { - var userClaims = JsonConvert.DeserializeObject>(model.UserClaimsItems); + var userClaims = JsonSerializer.Deserialize>(model.UserClaimsItems); api.UserClaims.AddRange(userClaims.Select(x => new ApiScopeClaim { diff --git a/src/Monolith/ClassifiedAds.IdentityServer/Controllers/IdentityResourceController.cs b/src/Monolith/ClassifiedAds.IdentityServer/Controllers/IdentityResourceController.cs index f28df1877..443a89ca2 100644 --- a/src/Monolith/ClassifiedAds.IdentityServer/Controllers/IdentityResourceController.cs +++ b/src/Monolith/ClassifiedAds.IdentityServer/Controllers/IdentityResourceController.cs @@ -1,13 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using ClassifiedAds.IdentityServer.Models.IdentityResourceModels; +using ClassifiedAds.IdentityServer.Models.IdentityResourceModels; using IdentityServer4.EntityFramework.DbContexts; using IdentityServer4.EntityFramework.Entities; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Newtonsoft.Json; +using System.Collections.Generic; +using System.Linq; +using System.Text.Json; namespace ClassifiedAds.IdentityServer.Controllers { @@ -63,7 +61,7 @@ public IActionResult Edit(IdentityResourceModel model) if (!string.IsNullOrEmpty(model.UserClaimsItems)) { - model.UserClaims = JsonConvert.DeserializeObject>(model.UserClaimsItems); + model.UserClaims = JsonSerializer.Deserialize>(model.UserClaimsItems); identity.UserClaims.AddRange(model.UserClaims.Select(x => new IdentityResourceClaim { diff --git a/src/Monolith/ClassifiedAds.IdentityServer/Models/ClientModels/ClientModel.cs b/src/Monolith/ClassifiedAds.IdentityServer/Models/ClientModels/ClientModel.cs index bc4bf4b9a..722a6b5a3 100644 --- a/src/Monolith/ClassifiedAds.IdentityServer/Models/ClientModels/ClientModel.cs +++ b/src/Monolith/ClassifiedAds.IdentityServer/Models/ClientModels/ClientModel.cs @@ -2,9 +2,9 @@ using IdentityServer4.EntityFramework.Entities; using IdentityServer4.EntityFramework.Mappers; using IdentityServer4.Models; -using Newtonsoft.Json; using System.Collections.Generic; using System.Linq; +using System.Text.Json; namespace ClassifiedAds.IdentityServer.Models.ClientModels { @@ -82,7 +82,7 @@ private List ConvertItems(string items) { return string.IsNullOrWhiteSpace(items) ? new List() - : JsonConvert.DeserializeObject>(items); + : JsonSerializer.Deserialize>(items); } public void UpdateEntity(IdentityServer4.EntityFramework.Entities.Client entity) diff --git a/src/Monolith/ClassifiedAds.IdentityServer/Quickstart/Diagnostics/DiagnosticsViewModel.cs b/src/Monolith/ClassifiedAds.IdentityServer/Quickstart/Diagnostics/DiagnosticsViewModel.cs index f43c7685b..70b5c0578 100644 --- a/src/Monolith/ClassifiedAds.IdentityServer/Quickstart/Diagnostics/DiagnosticsViewModel.cs +++ b/src/Monolith/ClassifiedAds.IdentityServer/Quickstart/Diagnostics/DiagnosticsViewModel.cs @@ -4,9 +4,9 @@ using IdentityModel; using Microsoft.AspNetCore.Authentication; -using Newtonsoft.Json; using System.Collections.Generic; using System.Text; +using System.Text.Json; namespace IdentityServerHost.Quickstart.UI { @@ -22,7 +22,7 @@ public DiagnosticsViewModel(AuthenticateResult result) var bytes = Base64Url.Decode(encoded); var value = Encoding.UTF8.GetString(bytes); - Clients = JsonConvert.DeserializeObject(value); + Clients = JsonSerializer.Deserialize(value); } } diff --git a/src/Monolith/ClassifiedAds.IdentityServer/TagHelpers/PickerTagHelper.cs b/src/Monolith/ClassifiedAds.IdentityServer/TagHelpers/PickerTagHelper.cs index 9e95c8558..79a0147c1 100644 --- a/src/Monolith/ClassifiedAds.IdentityServer/TagHelpers/PickerTagHelper.cs +++ b/src/Monolith/ClassifiedAds.IdentityServer/TagHelpers/PickerTagHelper.cs @@ -1,12 +1,9 @@ using Microsoft.AspNetCore.Html; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Razor.TagHelpers; -using Newtonsoft.Json; -using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Threading.Tasks; +using System.Text.Json; namespace ClassifiedAds.IdentityServer.TagHelpers { @@ -93,7 +90,7 @@ private void AddComponent(TagHelperOutput output) } }; - var rawPickerHtml = new HtmlString($"
"); + var rawPickerHtml = new HtmlString($"
"); output.Content.AppendHtml(rawPickerHtml); } diff --git a/src/Monolith/ClassifiedAds.Infrastructure/ClassifiedAds.Infrastructure.csproj b/src/Monolith/ClassifiedAds.Infrastructure/ClassifiedAds.Infrastructure.csproj index ea879647d..463731fc3 100644 --- a/src/Monolith/ClassifiedAds.Infrastructure/ClassifiedAds.Infrastructure.csproj +++ b/src/Monolith/ClassifiedAds.Infrastructure/ClassifiedAds.Infrastructure.csproj @@ -56,7 +56,6 @@ - diff --git a/src/Monolith/ClassifiedAds.Infrastructure/Interceptors/ErrorCatchingInterceptor.cs b/src/Monolith/ClassifiedAds.Infrastructure/Interceptors/ErrorCatchingInterceptor.cs index db197889a..aa0778b94 100644 --- a/src/Monolith/ClassifiedAds.Infrastructure/Interceptors/ErrorCatchingInterceptor.cs +++ b/src/Monolith/ClassifiedAds.Infrastructure/Interceptors/ErrorCatchingInterceptor.cs @@ -1,7 +1,8 @@ using Castle.DynamicProxy; using Microsoft.Extensions.Logging; -using Newtonsoft.Json; using System; +using System.Text.Json; +using System.Text.Json.Serialization; namespace ClassifiedAds.Infrastructure.Interceptors { @@ -27,7 +28,12 @@ public void Intercept(IInvocation invocation) var methodName = method.Name; // TODO: Ignore serialize large argument object. - var arguments = JsonConvert.SerializeObject(invocation.Arguments, Formatting.None, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); + var arguments = JsonSerializer.Serialize(invocation.Arguments, new JsonSerializerOptions() + { + WriteIndented = false, + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, + ReferenceHandler = ReferenceHandler.IgnoreCycles, + }); _logger.LogError($"An unhandled exception has occurred while executing the method: {className}.{methodName} with ({arguments}). {Environment.NewLine}{ex.ToString()}"); throw; } diff --git a/src/Monolith/ClassifiedAds.Infrastructure/Interceptors/LoggingInterceptor.cs b/src/Monolith/ClassifiedAds.Infrastructure/Interceptors/LoggingInterceptor.cs index e26bcf2bd..a28a1628a 100644 --- a/src/Monolith/ClassifiedAds.Infrastructure/Interceptors/LoggingInterceptor.cs +++ b/src/Monolith/ClassifiedAds.Infrastructure/Interceptors/LoggingInterceptor.cs @@ -1,7 +1,8 @@ using Castle.DynamicProxy; using Microsoft.Extensions.Logging; -using Newtonsoft.Json; using System.Diagnostics; +using System.Text.Json; +using System.Text.Json.Serialization; namespace ClassifiedAds.Infrastructure.Interceptors { @@ -19,7 +20,13 @@ public void Intercept(IInvocation invocation) var method = invocation.Method; var className = method.DeclaringType.Name; var methodName = method.Name; - var arguments = JsonConvert.SerializeObject(invocation.Arguments, Formatting.None, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); + + var arguments = JsonSerializer.Serialize(invocation.Arguments, new JsonSerializerOptions() + { + WriteIndented = false, + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, + ReferenceHandler = ReferenceHandler.IgnoreCycles, + }); _logger.LogDebug($"Start calling method: {className}.{methodName} with ({arguments})."); diff --git a/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventGrid/AzureEventGridSender.cs b/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventGrid/AzureEventGridSender.cs index 94fe52139..0b7cde3fd 100644 --- a/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventGrid/AzureEventGridSender.cs +++ b/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventGrid/AzureEventGridSender.cs @@ -1,9 +1,9 @@ using Azure; using Azure.Messaging.EventGrid; using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using System; using System.Collections.Generic; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -27,7 +27,7 @@ public async Task SendAsync(T message, MetaData metaData, CancellationToken canc EventGridPublisherClient client = new EventGridPublisherClient(new Uri(_domainEndpoint), new AzureKeyCredential(_domainKey)); - var data = new BinaryData(JsonConvert.SerializeObject(new Message + var data = new BinaryData(JsonSerializer.Serialize(new Message { Data = message, MetaData = metaData, diff --git a/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventHub/AzureEventHubReceiver.cs b/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventHub/AzureEventHubReceiver.cs index 415e620fa..b36db8c4d 100644 --- a/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventHub/AzureEventHubReceiver.cs +++ b/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventHub/AzureEventHubReceiver.cs @@ -3,9 +3,9 @@ using Azure.Messaging.EventHubs.Processor; using Azure.Storage.Blobs; using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using System; using System.Text; +using System.Text.Json; using System.Threading.Tasks; namespace ClassifiedAds.Infrastructure.MessageBrokers.AzureEventHub @@ -43,7 +43,7 @@ Task ProcessEventHandler(ProcessEventArgs eventArgs) try { var messageAsString = Encoding.UTF8.GetString(eventArgs.Data.EventBody); - var message = JsonConvert.DeserializeObject>(messageAsString); + var message = JsonSerializer.Deserialize>(messageAsString); action(message.Data, message.MetaData); } catch (Exception ex) diff --git a/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventHub/AzureEventHubSender.cs b/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventHub/AzureEventHubSender.cs index 9de932965..1d9961f56 100644 --- a/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventHub/AzureEventHubSender.cs +++ b/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureEventHub/AzureEventHubSender.cs @@ -1,8 +1,8 @@ using Azure.Messaging.EventHubs; using Azure.Messaging.EventHubs.Producer; using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using System.Collections.Generic; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -25,7 +25,7 @@ public async Task SendAsync(T message, MetaData metaData, CancellationToken canc var events = new List { - new EventData(JsonConvert.SerializeObject(new Message + new EventData(JsonSerializer.Serialize(new Message { Data = message, MetaData = metaData, diff --git a/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureQueue/AzureQueueReceiver.cs b/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureQueue/AzureQueueReceiver.cs index 8acab41b4..69bdf85b7 100644 --- a/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureQueue/AzureQueueReceiver.cs +++ b/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureQueue/AzureQueueReceiver.cs @@ -1,7 +1,7 @@ using Azure.Storage.Queues; using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using System; +using System.Text.Json; using System.Threading.Tasks; namespace ClassifiedAds.Infrastructure.MessageBrokers.AzureQueue @@ -28,7 +28,7 @@ private Task ReceiveAsync(Action action) { return ReceiveStringAsync(retrievedMessage => { - var message = JsonConvert.DeserializeObject>(retrievedMessage); + var message = JsonSerializer.Deserialize>(retrievedMessage); action(message.Data, message.MetaData); }); } diff --git a/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureQueue/AzureQueueSender.cs b/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureQueue/AzureQueueSender.cs index fb9c5dff6..1115ef6db 100644 --- a/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureQueue/AzureQueueSender.cs +++ b/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureQueue/AzureQueueSender.cs @@ -1,6 +1,6 @@ using Azure.Storage.Queues; using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -22,7 +22,7 @@ public async Task SendAsync(T message, MetaData metaData, CancellationToken canc var queueClient = new QueueClient(_connectionString, _queueName); await queueClient.CreateIfNotExistsAsync(cancellationToken: cancellationToken); - var jsonMessage = JsonConvert.SerializeObject(new Message + var jsonMessage = JsonSerializer.Serialize(new Message { Data = message, MetaData = metaData, diff --git a/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusReceiver.cs b/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusReceiver.cs index 1b75998d9..da4aaeebb 100644 --- a/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusReceiver.cs +++ b/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusReceiver.cs @@ -1,8 +1,8 @@ using Azure.Messaging.ServiceBus; using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using System; using System.Text; +using System.Text.Json; using System.Threading.Tasks; namespace ClassifiedAds.Infrastructure.MessageBrokers.AzureServiceBus @@ -27,7 +27,7 @@ private Task ReceiveAsync(Action action) { return ReceiveStringAsync(retrievedMessage => { - var message = JsonConvert.DeserializeObject>(retrievedMessage); + var message = JsonSerializer.Deserialize>(retrievedMessage); action(message.Data, message.MetaData); }); } diff --git a/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusSender.cs b/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusSender.cs index 7c309cfc7..1fc6881df 100644 --- a/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusSender.cs +++ b/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusSender.cs @@ -1,7 +1,7 @@ using Azure.Messaging.ServiceBus; using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using System.Text; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -22,7 +22,7 @@ public async Task SendAsync(T message, MetaData metaData, CancellationToken canc { await using var client = new ServiceBusClient(_connectionString); ServiceBusSender sender = client.CreateSender(_queueName); - var serviceBusMessage = new ServiceBusMessage(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new Message + var serviceBusMessage = new ServiceBusMessage(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(new Message { Data = message, MetaData = metaData, diff --git a/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusSubscriptionReceiver.cs b/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusSubscriptionReceiver.cs index 764912afe..15d9babbf 100644 --- a/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusSubscriptionReceiver.cs +++ b/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusSubscriptionReceiver.cs @@ -1,8 +1,8 @@ using Azure.Messaging.ServiceBus; using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using System; using System.Text; +using System.Text.Json; using System.Threading.Tasks; namespace ClassifiedAds.Infrastructure.MessageBrokers.AzureServiceBus @@ -29,7 +29,7 @@ private Task ReceiveAsync(Action action) { return ReceiveStringAsync(retrievedMessage => { - var message = JsonConvert.DeserializeObject>(retrievedMessage); + var message = JsonSerializer.Deserialize>(retrievedMessage); action(message.Data, message.MetaData); }); } diff --git a/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusTopicSender.cs b/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusTopicSender.cs index 940e24fa1..ed5aac057 100644 --- a/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusTopicSender.cs +++ b/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/AzureServiceBus/AzureServiceBusTopicSender.cs @@ -1,7 +1,7 @@ using Azure.Messaging.ServiceBus; using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using System.Text; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -22,7 +22,7 @@ public async Task SendAsync(T message, MetaData metaData, CancellationToken canc { await using var client = new ServiceBusClient(_connectionString); ServiceBusSender sender = client.CreateSender(_topicName); - var serviceBusMessage = new ServiceBusMessage(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new Message + var serviceBusMessage = new ServiceBusMessage(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(new Message { Data = message, MetaData = metaData, diff --git a/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/Kafka/KafkaReceiver.cs b/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/Kafka/KafkaReceiver.cs index cdcc39073..15a9423cd 100644 --- a/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/Kafka/KafkaReceiver.cs +++ b/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/Kafka/KafkaReceiver.cs @@ -1,7 +1,7 @@ using ClassifiedAds.Domain.Infrastructure.MessageBrokers; using Confluent.Kafka; -using Newtonsoft.Json; using System; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -61,7 +61,7 @@ private void StartReceiving(Action action, CancellationToken cancel continue; } - var message = JsonConvert.DeserializeObject>(consumeResult.Message.Value); + var message = JsonSerializer.Deserialize>(consumeResult.Message.Value); action(message.Data, message.MetaData); } catch (ConsumeException e) diff --git a/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/Kafka/KafkaSender.cs b/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/Kafka/KafkaSender.cs index 788bb3f7f..710116178 100644 --- a/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/Kafka/KafkaSender.cs +++ b/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/Kafka/KafkaSender.cs @@ -1,7 +1,7 @@ using ClassifiedAds.Domain.Infrastructure.MessageBrokers; using Confluent.Kafka; -using Newtonsoft.Json; using System; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -30,7 +30,7 @@ public async Task SendAsync(T message, MetaData metaData, CancellationToken canc { _ = await _producer.ProduceAsync(_topic, new Message { - Value = JsonConvert.SerializeObject(new Message + Value = JsonSerializer.Serialize(new Message { Data = message, MetaData = metaData, diff --git a/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/RabbitMQ/RabbitMQReceiver.cs b/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/RabbitMQ/RabbitMQReceiver.cs index 82d1d01a2..9a63e5ba1 100644 --- a/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/RabbitMQ/RabbitMQReceiver.cs +++ b/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/RabbitMQ/RabbitMQReceiver.cs @@ -1,9 +1,9 @@ using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using RabbitMQ.Client; using RabbitMQ.Client.Events; using System; using System.Text; +using System.Text.Json; namespace ClassifiedAds.Infrastructure.MessageBrokers.RabbitMQ { @@ -56,7 +56,7 @@ This tells RabbitMQ not to give more than one message to a worker at a time. consumer.Received += (model, ea) => { var body = Encoding.UTF8.GetString(ea.Body.Span); - var message = JsonConvert.DeserializeObject>(body); + var message = JsonSerializer.Deserialize>(body); action(message.Data, message.MetaData); _channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false); }; diff --git a/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/RabbitMQ/RabbitMQSender.cs b/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/RabbitMQ/RabbitMQSender.cs index 202a5ed10..bb317941c 100644 --- a/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/RabbitMQ/RabbitMQSender.cs +++ b/src/Monolith/ClassifiedAds.Infrastructure/MessageBrokers/RabbitMQ/RabbitMQSender.cs @@ -1,7 +1,7 @@ using ClassifiedAds.Domain.Infrastructure.MessageBrokers; -using Newtonsoft.Json; using RabbitMQ.Client; using System.Text; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -32,7 +32,7 @@ await Task.Run(() => { using var connection = _connectionFactory.CreateConnection(); using var channel = connection.CreateModel(); - var body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new Message + var body = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(new Message { Data = message, MetaData = metaData, diff --git a/src/Monolith/ClassifiedAds.WebAPI/Controllers/FilesController.cs b/src/Monolith/ClassifiedAds.WebAPI/Controllers/FilesController.cs index 63392a26f..5f305dff6 100644 --- a/src/Monolith/ClassifiedAds.WebAPI/Controllers/FilesController.cs +++ b/src/Monolith/ClassifiedAds.WebAPI/Controllers/FilesController.cs @@ -15,7 +15,6 @@ using Microsoft.AspNetCore.SignalR; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Localization; -using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; @@ -23,6 +22,7 @@ using System.Net; using System.Net.Mime; using System.Security.Cryptography; +using System.Text.Json; using System.Threading.Tasks; namespace ClassifiedAds.WebAPI.Controllers @@ -179,7 +179,7 @@ public async Task>> GetAuditLogs(Guid FileEntry previous = null; foreach (var log in logs.OrderBy(x => x.CreatedDateTime)) { - var data = JsonConvert.DeserializeObject(log.Log); + var data = JsonSerializer.Deserialize(log.Log); var highLight = new { Name = previous != null && data.Name != previous.Name, diff --git a/src/Monolith/ClassifiedAds.WebAPI/Controllers/ProductsController.cs b/src/Monolith/ClassifiedAds.WebAPI/Controllers/ProductsController.cs index 37fff1389..89ecea79f 100644 --- a/src/Monolith/ClassifiedAds.WebAPI/Controllers/ProductsController.cs +++ b/src/Monolith/ClassifiedAds.WebAPI/Controllers/ProductsController.cs @@ -15,12 +15,12 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; -using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Mime; +using System.Text.Json; using System.Threading.Tasks; namespace ClassifiedAds.WebAPI.Controllers @@ -129,7 +129,7 @@ public async Task>> GetAuditLogs(Guid ProductDTO previous = null; foreach (var log in logs.OrderBy(x => x.CreatedDateTime)) { - var data = JsonConvert.DeserializeObject(log.Log); + var data = JsonSerializer.Deserialize(log.Log); var highLight = new { Code = previous != null && data.Code != previous.Code,