DeliveryApi: Ensure the ContentType property is serialized first

This is needed so it can be used as a discriminator field by System.Text.Json
Changed both ApiElement and IApiElement to ensure not only ApiContentResponse,
but also ApiBlockItem, which uses the interface directly, are adjusted.
This commit is contained in:
Vitor Rodrigues
2023-08-27 11:11:02 +02:00
committed by Sebastiaan Janssen
parent 4d80073547
commit efe00910f3
2 changed files with 10 additions and 0 deletions

View File

@@ -1,3 +1,5 @@
using System.Text.Json.Serialization;
namespace Umbraco.Cms.Core.Models.DeliveryApi;
public class ApiElement : IApiElement
@@ -11,6 +13,9 @@ public class ApiElement : IApiElement
public Guid Id { get; }
// Ensure the ContentType property is serialized first
// This is needed so it can be used as a discriminator field by System.Text.Json
[JsonPropertyOrder(-100)]
public string ContentType { get; }
public IDictionary<string, object?> Properties { get; }

View File

@@ -1,9 +1,14 @@
using System.Text.Json.Serialization;
namespace Umbraco.Cms.Core.Models.DeliveryApi;
public interface IApiElement
{
Guid Id { get; }
// Ensure the ContentType property is serialized first
// This is needed so it can be used as a discriminator field by System.Text.Json
[JsonPropertyOrder(-100)]
string ContentType { get; }
IDictionary<string, object?> Properties { get; }