From e990a466aae68d2740281271b5e92d287a3f0923 Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 10 Sep 2025 15:38:05 +0200 Subject: [PATCH] refactor(AnnotationHandler): update to use System.Text.Json.JsonSerializer --- .../DocSigned/Handlers/AnnotationHandler.cs | 7 +++---- .../DocSigned/Handlers/HistoryHandler.cs | 4 +--- EnvelopeGenerator.Domain/Constants/Format.cs | 16 ++++++++++++---- .../Controllers/EnvelopeController.cs | 14 +++++++------- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/EnvelopeGenerator.Application/Common/Notifications/DocSigned/Handlers/AnnotationHandler.cs b/EnvelopeGenerator.Application/Common/Notifications/DocSigned/Handlers/AnnotationHandler.cs index cdebb011..fdf43468 100644 --- a/EnvelopeGenerator.Application/Common/Notifications/DocSigned/Handlers/AnnotationHandler.cs +++ b/EnvelopeGenerator.Application/Common/Notifications/DocSigned/Handlers/AnnotationHandler.cs @@ -1,8 +1,7 @@ -using EnvelopeGenerator.Application.Common.Notifications.DocSigned; -using EnvelopeGenerator.Application.DocStatus.Commands; +using EnvelopeGenerator.Application.DocStatus.Commands; using EnvelopeGenerator.Domain.Constants; using MediatR; -using Newtonsoft.Json; +using System.Text.Json; namespace EnvelopeGenerator.Application.Common.Notifications.DocSigned.Handlers; @@ -34,7 +33,7 @@ public class AnnotationHandler : INotificationHandler { Envelope = new() { Id = notification.EnvelopeId }, Receiver = new() { Id = notification.ReceiverId}, - Value = JsonConvert.SerializeObject(notification.Annotations, Format.Json.ForAnnotations) + Value = JsonSerializer.Serialize(notification.Annotations, Format.Json.ForAnnotations) }, cancel); } } \ No newline at end of file diff --git a/EnvelopeGenerator.Application/Common/Notifications/DocSigned/Handlers/HistoryHandler.cs b/EnvelopeGenerator.Application/Common/Notifications/DocSigned/Handlers/HistoryHandler.cs index c15e177f..409edf59 100644 --- a/EnvelopeGenerator.Application/Common/Notifications/DocSigned/Handlers/HistoryHandler.cs +++ b/EnvelopeGenerator.Application/Common/Notifications/DocSigned/Handlers/HistoryHandler.cs @@ -1,5 +1,4 @@ -using EnvelopeGenerator.Application.Common.Notifications.DocSigned; -using EnvelopeGenerator.Application.Histories.Commands; +using EnvelopeGenerator.Application.Histories.Commands; using EnvelopeGenerator.Domain.Constants; using MediatR; using Newtonsoft.Json; @@ -39,7 +38,6 @@ public class HistoryHandler : INotificationHandler EnvelopeId = notification.EnvelopeId, UserReference = notification.Receiver.EmailAddress, Status = EnvelopeStatus.DocumentSigned, - Comment = JsonConvert.SerializeObject(notification.Annotations, Format.Json.ForAnnotations) }, cancel); } } \ No newline at end of file diff --git a/EnvelopeGenerator.Domain/Constants/Format.cs b/EnvelopeGenerator.Domain/Constants/Format.cs index 1f131e5e..88f30f32 100644 --- a/EnvelopeGenerator.Domain/Constants/Format.cs +++ b/EnvelopeGenerator.Domain/Constants/Format.cs @@ -1,5 +1,9 @@ using Newtonsoft.Json; using Newtonsoft.Json.Serialization; +#if NET +using System.Text.Json; +using System.Text.Json.Serialization; +#endif namespace EnvelopeGenerator.Domain.Constants { @@ -8,18 +12,22 @@ namespace EnvelopeGenerator.Domain.Constants #region Json Serializer Settings public static class Json { + //TODO: update to use System.Text.Json public static readonly JsonSerializerSettings ForDiagnostics = new JsonSerializerSettings() { ContractResolver = new CamelCasePropertyNamesContractResolver(), Formatting = Formatting.Indented, NullValueHandling = NullValueHandling.Include }; - public static readonly JsonSerializerSettings ForAnnotations = new JsonSerializerSettings() + +#if NET + public static readonly JsonSerializerOptions ForAnnotations = new() { - ContractResolver = new CamelCasePropertyNamesContractResolver(), - Formatting = Formatting.None, - NullValueHandling = NullValueHandling.Ignore + PropertyNamingPolicy = JsonNamingPolicy.CamelCase, + WriteIndented = false, + DefaultIgnoreCondition = JsonIgnoreCondition.Never, }; +#endif } #endregion } diff --git a/EnvelopeGenerator.Web/Controllers/EnvelopeController.cs b/EnvelopeGenerator.Web/Controllers/EnvelopeController.cs index 098a4d21..886443ad 100644 --- a/EnvelopeGenerator.Web/Controllers/EnvelopeController.cs +++ b/EnvelopeGenerator.Web/Controllers/EnvelopeController.cs @@ -1,15 +1,15 @@ -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; +using DigitalData.Core.Abstraction.Application.DTO; +using DigitalData.Core.Exceptions; +using EnvelopeGenerator.Application.Common.Extensions; +using EnvelopeGenerator.Application.Common.Notifications.DocSigned; +using EnvelopeGenerator.Application.EnvelopeReceivers.Queries; using EnvelopeGenerator.Application.Interfaces.Services; using EnvelopeGenerator.Domain.Constants; -using DigitalData.Core.Abstraction.Application.DTO; using EnvelopeGenerator.Web.Extensions; using MediatR; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; using System.Dynamic; -using EnvelopeGenerator.Application.EnvelopeReceivers.Queries; -using DigitalData.Core.Exceptions; -using EnvelopeGenerator.Application.Common.Notifications.DocSigned; -using EnvelopeGenerator.Application.Common.Extensions; namespace EnvelopeGenerator.Web.Controllers;