refactor(AnnotationHandler): update to use System.Text.Json.JsonSerializer

This commit is contained in:
tekh 2025-09-10 15:38:05 +02:00
parent 4eb6d87770
commit e990a466aa
4 changed files with 23 additions and 18 deletions

View File

@ -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<DocSignedNotification>
{
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);
}
}

View File

@ -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<DocSignedNotification>
EnvelopeId = notification.EnvelopeId,
UserReference = notification.Receiver.EmailAddress,
Status = EnvelopeStatus.DocumentSigned,
Comment = JsonConvert.SerializeObject(notification.Annotations, Format.Json.ForAnnotations)
}, cancel);
}
}

View File

@ -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
}

View File

@ -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;