D365 Commerce : Omitting serialization of null and default values in JSON payloads

I have always been interested in how to improve performance, and I have understood that there is no silver bullet or switch you just can turn to get dramatically improvements. The path towards performance is a delicate balance between functionality, usability, scalability and effort/budget. Together with friends, I think we have found some low-hanging fruits that may shave of milliseconds for POS and eCommerce API’s, but we need your help. If you would like this feature to become available, please use the community superpower() and vote on the following idea:

https://experience.dynamics.com/ideas/idea/?ideaid=9cbbf368-a614-ed11-b5cf-0003ff45afb4

To explain the idea, when the POS and eCommerce is communicating with CSU(Commerce Scale Unit), then JSON is used as the lightweight data-interchange format. It is easy for us humans to read and it is easy for machines to parse and generate. Let’s take a concrete example. When looking up a product, then the attributes of that product is shown, and in the following example I only have one attribute; Item number, but the JSON still contains the complete structure. Sending null and default values is just taking space without transferring any actual information.

Any data we are sending will affect processing of the JSON, and networking time to transfer the messages. By further minimizing the JSON messages we can improve the response times and the performance experience. The JSON generators used with Dynamics 365 to have the capability to omit null and default values, and it is a very small switch to enable, that could reduce the payload quite dramatically (up to 40%-50% on products and product attributes).

Here is a small C# sample code on how to reduce the JSON payload using the JsonSerializerOptions to omit null and default values.

——————————————-

using System.Runtime.Serialization;

using System.Text.Json;

using System.Text.Json.Serialization;

 

[DataContract]

public class TestClass

{

   [DataMember]

    public bool B1 { getset; }

   [DataMember]

    public bool B2 { getset; }

   [DataMember]

    public string? S3 { getset; }

}

 

class Program

{

    static void Main()

   {

       TestClass tc = new() {B1 = true};

       JsonSerializerOptions options = new JsonSerializerOptions();

        options.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault;

        var serialized = JsonSerializer.Serialize(tc, options);

       Console.WriteLine(serialized);

   }

}

Prints: {“B1”:true}

————————————————

If you agree with me, then please vote on the idea, so that Microsoft can implement this performance improvement into future releases.

 

Thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.