System.Text.JSON in web api

We have our own Web API controllers and am finding that the deserialisation of models is using Newtonsoft (because of Umbraco I believe) and not System.Text.JSON is there a way for force it?

I’ve tried a custom model binder but this didn’t seem to work.

using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace Web.Global.Core.Models.Broker.Requests
{
    public class OrderStatusRequest
    {
        [JsonPropertyName("csiOrderId")]
        public string CsiOrderId { get; set; }

        // we have to add this line and add Newtonsoft.Json to get the model binding to work, which we don't want to do
        [JsonProperty("ecomOrderNumber")]

        // this line JsonPropertyName is ignored from System.Text.Json, and the OrderNumber property is null
        [JsonPropertyName("ecomOrderNumber")]
        public string OrderNumber { get; set; }

        [JsonPropertyName("status")]
        public int OrderStatus { get; set; }

        [JsonPropertyName("orderLines")]
        public List<OrderStatusRequestOrderLine> OrderLines { get; set; }
    }
}

What are you using to trying to serialize/deserialize them with? If you try using Newtonsoft to serialize, then yeah, it won’t recognize the JsonPropertyName attribute.
Try using JsonSerializer.Serialize() and see if that works better.

Try checking out: How to serialize JSON in C# - .NET | Microsoft Learn
and maybe you’ll find what you’re looking for :slight_smile: