From c304bf07cbe5117fb57289f99c7d7dbbfd1b00f4 Mon Sep 17 00:00:00 2001 From: Elitsa Marinovska Date: Tue, 27 Oct 2020 15:44:11 +0100 Subject: [PATCH] Registering UdiJsonConverter globally so that we can migrate EntityBasic to Umbraco.Core --- .../Models/ContentEditing/EntityBasic.cs | 5 +---- .../ModelBinding/UmbracoJsonModelBinderProvider.cs | 7 ++++--- 2 files changed, 5 insertions(+), 7 deletions(-) rename src/{Umbraco.Infrastructure => Umbraco.Core}/Models/ContentEditing/EntityBasic.cs (93%) diff --git a/src/Umbraco.Infrastructure/Models/ContentEditing/EntityBasic.cs b/src/Umbraco.Core/Models/ContentEditing/EntityBasic.cs similarity index 93% rename from src/Umbraco.Infrastructure/Models/ContentEditing/EntityBasic.cs rename to src/Umbraco.Core/Models/ContentEditing/EntityBasic.cs index 4776983687..946fd2102a 100644 --- a/src/Umbraco.Infrastructure/Models/ContentEditing/EntityBasic.cs +++ b/src/Umbraco.Core/Models/ContentEditing/EntityBasic.cs @@ -3,10 +3,8 @@ using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Runtime.Serialization; -using Newtonsoft.Json; using Umbraco.Core; using Umbraco.Core.Models.Validation; -using Umbraco.Core.Serialization; namespace Umbraco.Web.Models.ContentEditing { @@ -28,7 +26,6 @@ namespace Umbraco.Web.Models.ContentEditing [DataMember(Name = "udi")] [ReadOnly(true)] - [JsonConverter(typeof(UdiJsonConverter))] public Udi Udi { get; set; } [DataMember(Name = "icon")] @@ -61,7 +58,7 @@ namespace Umbraco.Web.Models.ContentEditing /// The path of the entity /// [DataMember(Name = "path")] - public string Path { get; set; } + public string Path { get; set; } /// /// A collection of extra data that is available for this specific entity/entity type /// diff --git a/src/Umbraco.Web.Common/ModelBinding/UmbracoJsonModelBinderProvider.cs b/src/Umbraco.Web.Common/ModelBinding/UmbracoJsonModelBinderProvider.cs index 94b5b37c82..5543d05d3e 100644 --- a/src/Umbraco.Web.Common/ModelBinding/UmbracoJsonModelBinderProvider.cs +++ b/src/Umbraco.Web.Common/ModelBinding/UmbracoJsonModelBinderProvider.cs @@ -6,9 +6,7 @@ using Microsoft.AspNetCore.Mvc.ModelBinding.Binders; using Microsoft.Extensions.Logging; using Microsoft.Extensions.ObjectPool; using System.Buffers; -using System.Reflection; -using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; +using Umbraco.Core.Serialization; using Umbraco.Web.Common.Formatters; namespace Umbraco.Web.Common.ModelBinding @@ -32,6 +30,9 @@ namespace Umbraco.Web.Common.ModelBinding var ss = jsonOptions.SerializerSettings; // Just use the defaults as base + // Register UdiJsonConverter globally + ss.Converters.Add(new UdiJsonConverter()); + // We need to ignore required attributes when serializing. E.g UserSave.ChangePassword. Otherwise the model is not model bound. ss.ContractResolver = new IgnoreRequiredAttributesResolver(); return new IInputFormatter[]