From d10f19d92a67ddbae1b2972359f405828b41c4c8 Mon Sep 17 00:00:00 2001 From: TekH Date: Mon, 13 Oct 2025 16:56:00 +0200 Subject: [PATCH] refactor(annotation): add lazy JSON deserialization for PSPDFKitInstantJSON - Introduced Lazy field for deferred deserialization of PSPDFKitInstantJSON - Added ExpandoObject property (PSPDFKitInstant) for dynamic access - Updated handler to use ParsePSPDFKitInstant instead of ParsePSPDFKitInstantJSON - Improved JsonSerializerOptions for case-insensitive property handling --- .../Commands/CreateAnnotationCommand.cs | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/EnvelopeGenerator.Application/Annotations/Commands/CreateAnnotationCommand.cs b/EnvelopeGenerator.Application/Annotations/Commands/CreateAnnotationCommand.cs index 81d78eb8..87758a4f 100644 --- a/EnvelopeGenerator.Application/Annotations/Commands/CreateAnnotationCommand.cs +++ b/EnvelopeGenerator.Application/Annotations/Commands/CreateAnnotationCommand.cs @@ -5,6 +5,8 @@ using EnvelopeGenerator.Application.Common.Query; using EnvelopeGenerator.Domain.Entities; using MediatR; using Microsoft.EntityFrameworkCore; +using System.Dynamic; +using System.Text.Json; using System.Text.Json.Serialization; namespace EnvelopeGenerator.Application.Annotations.Commands; @@ -14,11 +16,36 @@ namespace EnvelopeGenerator.Application.Annotations.Commands; /// public record CreateAnnotationCommand : EnvelopeReceiverQueryBase, IRequest> { + /// + /// + /// + public CreateAnnotationCommand() + { + _lazyPSPDFKitInstant = new(() => + { + var options = new JsonSerializerOptions + { + PropertyNameCaseInsensitive = true, + PropertyNamingPolicy = null + }; + + return JsonSerializer.Deserialize(PSPDFKitInstantJSON, options) ?? new ExpandoObject(); + }); + } + /// /// /// [JsonIgnore] public string PSPDFKitInstantJSON { get; set; } = null!; + + private readonly Lazy _lazyPSPDFKitInstant; + + /// + /// + /// + [JsonIgnore] + public ExpandoObject PSPDFKitInstant => _lazyPSPDFKitInstant.Value; } /// @@ -72,7 +99,7 @@ public class CreateAnnotationCommandHandler : IRequestHandler new Annotation() { ElementId = element.Id, @@ -90,10 +117,10 @@ public class CreateAnnotationCommandHandler : IRequestHandler /// /// - /// + /// /// /// - public static Dictionary ParsePSPDFKitInstantJSON(string json, int elementId) + public static Dictionary ParsePSPDFKitInstant(ExpandoObject instant, int elementId) { Dictionary annots = new();