Configurable JSON serialization support (Newtonsoft.Json vs System.Text.Json) #711

Open
opened 2025-12-29 08:32:49 +01:00 by adam · 9 comments
Owner

Originally created by @serber on GitHub (Aug 1, 2025).

Originally assigned to: @StefH on GitHub.

WireMock.Net forces me to use Newtonsoft.Json as the only serialization option. In modern .NET applications that have migrated to System.Text.Json, this creates dependency conflicts, performance overhead, and inconsistent serialization behavior between production code and test mocks. When my application uses System.Text.Json with specific naming policies and converters, WireMock's Newtonsoft.Json serialization can produce different results, leading to unreliable tests that don't accurately reflect production behavior.

I would like WireMock.Net to support configurable JSON serialization, allowing users to choose between Newtonsoft.Json (current default) and System.Text.Json. This could be implemented through:

// Configuration option
WireMockServer.Start(new WireMockServerSettings
{
    JsonSerializer = JsonSerializerType.SystemTextJson
});

// Or fluent API
var server = WireMockServer
    .Start()
    .UseSystemTextJson()
    .WithSettings(settings);

Additional context

  • System.Text.Json offers significantly better performance (up to 2x faster serialization)
  • Many .NET 5+ projects have migrated away from Newtonsoft.Json
  • Microsoft recommends System.Text.Json for new applications
  • This feature would help WireMock.Net stay current with .NET ecosystem trends
  • Backward compatibility can be maintained by keeping Newtonsoft.Json as the default option
  • Would be valuable for high-throughput testing scenarios where serialization performance matters
Originally created by @serber on GitHub (Aug 1, 2025). Originally assigned to: @StefH on GitHub. WireMock.Net forces me to use `Newtonsoft.Json` as the only serialization option. In modern .NET applications that have migrated to `System.Text.Json`, this creates dependency conflicts, performance overhead, and inconsistent serialization behavior between production code and test mocks. When my application uses `System.Text.Json` with specific naming policies and converters, WireMock's `Newtonsoft.Json` serialization can produce different results, leading to unreliable tests that don't accurately reflect production behavior. I would like WireMock.Net to support configurable JSON serialization, allowing users to choose between `Newtonsoft.Json` (current default) and `System.Text.Json`. This could be implemented through: ```csharp // Configuration option WireMockServer.Start(new WireMockServerSettings { JsonSerializer = JsonSerializerType.SystemTextJson }); // Or fluent API var server = WireMockServer .Start() .UseSystemTextJson() .WithSettings(settings); ``` ### Additional context - `System.Text.Json` offers significantly better performance (up to 2x faster serialization) - Many .NET 5+ projects have migrated away from `Newtonsoft.Json` - Microsoft recommends `System.Text.Json` for new applications - This feature would help WireMock.Net stay current with .NET ecosystem trends - Backward compatibility can be maintained by keeping `Newtonsoft.Json` as the default option - Would be valuable for high-throughput testing scenarios where serialization performance matters
adam added the feature label 2025-12-29 08:32:49 +01:00
Author
Owner

@StefH commented on GitHub (Aug 11, 2025):

@serber
Note that it's already possible to provide the json serializer here:
https://github.com/wiremock/WireMock.Net/blob/master/src/WireMock.Net.Minimal/ResponseBuilders/Response.WithBody.cs#L217

Or do you mean something else?

@StefH commented on GitHub (Aug 11, 2025): @serber Note that it's already possible to provide the json serializer here: https://github.com/wiremock/WireMock.Net/blob/master/src/WireMock.Net.Minimal/ResponseBuilders/Response.WithBody.cs#L217 Or do you mean something else?
Author
Owner

@molander-dev commented on GitHub (Aug 21, 2025):

@serber Note that it's already possible to provide the json serializer here: https://github.com/wiremock/WireMock.Net/blob/master/src/WireMock.Net.Minimal/ResponseBuilders/Response.WithBody.cs#L217

Or do you mean something else?

Yeah its not about the serializer used in wiremock, its that wiremock globally sets Newtonsoft for the project you install Wiremock.NET to. So if our project uses System.Text and we install the Wiremock.NET package it breaks all our code that uses the System.Text.Json.JsonSerializer

@molander-dev commented on GitHub (Aug 21, 2025): > [@serber](https://github.com/serber) Note that it's already possible to provide the json serializer here: https://github.com/wiremock/WireMock.Net/blob/master/src/WireMock.Net.Minimal/ResponseBuilders/Response.WithBody.cs#L217 > > Or do you mean something else? Yeah its not about the serializer used in wiremock, its that wiremock globally sets Newtonsoft for the project you install Wiremock.NET to. So if our project uses System.Text and we install the Wiremock.NET package it breaks all our code that uses the System.Text.Json.JsonSerializer
Author
Owner

@StefH commented on GitHub (Aug 21, 2025):

Normally you would install WireMock.Net in a unit test project.
And I do not understand how adding WireMock.Net breaks / changes the json serializer used.

Can you please provide a complete example?

@StefH commented on GitHub (Aug 21, 2025): Normally you would install WireMock.Net in a unit test project. And I do not understand how adding WireMock.Net breaks / changes the json serializer used. Can you please provide a complete example?
Author
Owner

@molander-dev commented on GitHub (Aug 25, 2025):

Normally you would install WireMock.Net in a unit test project. And I do not understand how adding WireMock.Net breaks / changes the json serializer used.

Can you please provide a complete example?

Yes here's an example.

Before installing WireMock.NET package to my NUnit test project I have this helper class.

public class DateTimeHelper : JsonConverterFactory
{
   public override bool CanConvert(Type typeToConvert)
   {
      return typeToConvert == typeof(DateTime) || typeToConvert == typeof(DateTime?);
   }

   public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options)
   {
      if (typeToConvert == typeof(DateTime))
      {
         return new DateTimeConverter();
      }
      else if (typeToConvert == typeof(DateTime?))
      {
         return new NullableDateTimeConverter();
      }

      throw new InvalidOperationException($"Cannot create converter for {typeToConvert}");
   }

   public static string? GetDateAsString(DateTime? dateTime) => dateTime?.ToString("yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture);
}

After installing the Wiremock.NET to the project this method breaks and this part will say JsonConverter is a namespace but is used as a type.

public override JsonConverter CreateConverter(Type typeToConvert)

So then we need to add a custom using to keep using system.text

using STJsonConverter = System.Text.Json.Serialization.JsonConverter;

public override STJsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options)
@molander-dev commented on GitHub (Aug 25, 2025): > Normally you would install WireMock.Net in a unit test project. And I do not understand how adding WireMock.Net breaks / changes the json serializer used. > > Can you please provide a complete example? Yes here's an example. Before installing WireMock.NET package to my NUnit test project I have this helper class. ```csharp public class DateTimeHelper : JsonConverterFactory { public override bool CanConvert(Type typeToConvert) { return typeToConvert == typeof(DateTime) || typeToConvert == typeof(DateTime?); } public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) { if (typeToConvert == typeof(DateTime)) { return new DateTimeConverter(); } else if (typeToConvert == typeof(DateTime?)) { return new NullableDateTimeConverter(); } throw new InvalidOperationException($"Cannot create converter for {typeToConvert}"); } public static string? GetDateAsString(DateTime? dateTime) => dateTime?.ToString("yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture); } ``` After installing the Wiremock.NET to the project this method breaks and this part will say JsonConverter is a namespace but is used as a type. ```csharp public override JsonConverter CreateConverter(Type typeToConvert) ``` So then we need to add a custom using to keep using system.text ```csharp using STJsonConverter = System.Text.Json.Serialization.JsonConverter; public override STJsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) ```
Author
Owner

@tavisca-mjadhav commented on GitHub (Dec 4, 2025):

Hello @StefH

Yes I agree with @serber . Even I have a scenario where Newtonsoft.Json actually breaking during the HTTP recording phase.
In my case the my .net application is using the System.Text.Json serializer in all cases. In one of the use case, my application is making 3rd part call over the HTTPS network sending & receiving JSON data. This call is authenticated, as part of "SHA" body hash authentication mechanism, & the application computes the HASH value of the body by converting the request using System.Text.Json serializer to string. This SHA value is passed via header.

Now when I use proxy recording feature of the wiremock, to perform the recording of the outgoing call, Wiremock internally tries to parse the outgoing http request payload as JSON using newtonsoft JSON, and then it forwarded to actually 3'rd party service.
At this moment i receive unauthorized error. This is because of the difference in Hash value when HASH is computed via System.Text.Json and Newtonsoft.Json string serialization. There is different behavior used by System.Text.Json when it comes to serialize the special characters & encoding as compared to NewtonSoft.Json.

system-text-json/character-encoding .

  • By default System.text.Json escape HTML-sensitive characters such as <, >, &, and '.
  • Newtonsoft.Json, by default, does not escape HTML-sensitive characters such as <, >, &, and ' during serialization in the same way that System.Text.Json does for defense-in-depth against XSS or information-disclosure attacks.

Due to this difference in behavior, the HASH value computed before sending the call over the network & after receiving over the network for verification by the 3'rd party service is different (Though body has the same Json value).

So allowing Wiremock to choose between desired serializer will be of more helpful.

@tavisca-mjadhav commented on GitHub (Dec 4, 2025): Hello @StefH Yes I agree with @serber . Even I have a scenario where Newtonsoft.Json actually breaking during the HTTP recording phase. In my case the my .net application is using the System.Text.Json serializer in all cases. In one of the use case, my application is making 3rd part call over the HTTPS network sending & receiving JSON data. This call is authenticated, as part of "SHA" body hash authentication mechanism, & the application computes the HASH value of the body by converting the request using System.Text.Json serializer to string. This SHA value is passed via header. Now when I use proxy recording feature of the wiremock, to perform the recording of the outgoing call, Wiremock internally tries to parse the outgoing http request payload as JSON using newtonsoft JSON, and then it forwarded to actually 3'rd party service. At this moment i receive unauthorized error. This is because of the difference in Hash value when HASH is computed via System.Text.Json and Newtonsoft.Json string serialization. There is different behavior used by System.Text.Json when it comes to serialize the special characters & encoding as compared to NewtonSoft.Json. [system-text-json/character-encoding](https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/character-encoding) . - By default System.text.Json escape HTML-sensitive characters such as <, >, &, and '. - Newtonsoft.Json, by default, does not escape HTML-sensitive characters such as <, >, &, and ' during serialization in the same way that System.Text.Json does for defense-in-depth against XSS or information-disclosure attacks. Due to this difference in behavior, the HASH value computed before sending the call over the network & after receiving over the network for verification by the 3'rd party service is different (Though body has the same Json value). So allowing Wiremock to choose between desired serializer will be of more helpful.
Author
Owner

@StefH commented on GitHub (Dec 5, 2025):

@tavisca-mjadhav
Did you try this?

It's already possible to provide the json serializer here:
https://github.com/wiremock/WireMock.Net/blob/master/src/WireMock.Net.Minimal/ResponseBuilders/Response.WithBody.cs#L217

@StefH commented on GitHub (Dec 5, 2025): @tavisca-mjadhav Did you try this? > It's already possible to provide the json serializer here: https://github.com/wiremock/WireMock.Net/blob/master/src/WireMock.Net.Minimal/ResponseBuilders/Response.WithBody.cs#L217
Author
Owner

@tavisca-mjadhav commented on GitHub (Dec 11, 2025):

@tavisca-mjadhav Did you try this?

It's already possible to provide the json serializer here:
https://github.com/wiremock/WireMock.Net/blob/master/src/WireMock.Net.Minimal/ResponseBuilders/Response.WithBody.cs#L217

@StefH yes. I have already given it a try.
The problem is, System.Text.Json by default handles & escapes NonAscii & Html characters. But in Newtonsoft.Json Since the StringEscapeHandling is not a [Flags] enum , I can only use either StringEscapeHandling.EscapeNonAscii or StringEscapeHandling.EscapeHtml, but not both.

Not even custom converter supports this.
Due to this, the Wiremock recorded files will either have escaped Html characters or escaped NonAscii characters but not both, which is again causing the HASH difference as mentioned in above comment.

//This is not supported
 var jsonSerializerSettings = new Newtonsoft.Json.JsonSerializerSettings
 {
     StringEscapeHandling = StringEscapeHandling.EscapeHtml | StringEscapeHandling.EscapeNonAscii,  //NOT SUPPORTED
     Formatting = Formatting.Indented
 };

  using System;
  using System.Text.Encodings.Web;
  using System.Text.Json;
  using System.Text.Unicode;
  using Newtonsoft.Json;

  public class Program
  {
    public static void Main()
    {
        Console.WriteLine(("\\u" + string.Format("{0:X4}", (int)127).ToUpper()));
        var options1 = new System.Text.Json.JsonSerializerOptions
        {
            WriteIndented = true
        };

        var options2 = new Newtonsoft.Json.JsonSerializerSettings
        {
            StringEscapeHandling = StringEscapeHandling.EscapeNonAscii,
            Formatting = Formatting.Indented
        };
        //options2.Converters.Add(new UppercaseUnicodeStringConverter());
        var objec = new SpecialCharacters
        {
            Accents = "e.g. ©, ®, €, £, ¥, µ.",
            Scripts = "漢 (Chinese), こんにちは (Japanese), السلام عليكم (Arabic).",
            Symbols = "©, ®, €, £, ¥, µ.",
            CJK = "漢 (Chinese), こんにちは (Japanese), السلام عليكم (Arabic).",
            CJKSymbols = "©, ®, €, £, ¥, µ.",
            Emojis = "😀, 👍, ❤️. ",
            NonAscii = "a  , o, u, ñ.",
            HtmlSpecialCharacters = "<, >, &, ', \")"
        };


        var sysTextString = System.Text.Json.JsonSerializer.Serialize(objec, options1);
        Console.WriteLine(sysTextString);
        var nwtonString = Newtonsoft.Json.JsonConvert.SerializeObject(objec, options2);
        Console.WriteLine(nwtonString);

        var o1 = System.Text.Json.JsonSerializer.Deserialize<SpecialCharacters>(nwtonString);
        var o2 = Newtonsoft.Json.JsonConvert.DeserializeObject<SpecialCharacters>(sysTextString);
        Console.WriteLine("Accents  :" + string.Equals(o1.Accents, o2.Accents));
        Console.WriteLine("CJK  :" + string.Equals(o1.CJK, o2.CJK));
        Console.WriteLine("CJKSymbols  :" + string.Equals(o1.CJKSymbols, o2.CJKSymbols));
        Console.WriteLine("Emojis  :" + string.Equals(o1.Emojis, o2.Emojis));
        Console.WriteLine("HtmlSpecialCharacters  :" + string.Equals(o1.HtmlSpecialCharacters, o2.HtmlSpecialCharacters));
        Console.WriteLine("NonAscii  :" + string.Equals(o1.NonAscii, o2.NonAscii));
        Console.WriteLine("Symbols  :" + string.Equals(o1.Symbols, o2.Symbols));
        Console.WriteLine("Scripts  :" + string.Equals(o1.Scripts, o2.Scripts));

    }
 }

 public class SpecialCharacters
 {
    public string Accents { get; set; }
    public string Scripts { get; set; }
    public string Symbols { get; set; }
    public string CJK { get; set; }
    public string CJKSymbols { get; set; }
    public string Emojis { get; set; }
    public string NonAscii { get; set; }
    public string HtmlSpecialCharacters { get; set; }
 }

 public class UppercaseUnicodeStringConverter : Newtonsoft.Json.JsonConverter
 {
    // List of HTML special characters to escape
    private static readonly char[] HtmlSpecialChars = { '<', '>', '&', '\'', '"' };

    public override bool CanConvert(Type objectType)
    {
        return objectType == typeof(string);
    }

    public override void WriteJson(JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
    {
        string input = value as string;
        if (input == null)
        {
            writer.WriteNull();
            return;
        }

        var result = new System.Text.StringBuilder();

        foreach (char c in input)
        {
            // Escape HTML special characters
            if (Array.IndexOf(HtmlSpecialChars, c) >= 0)
            {
                // result.Append(System.Text.RegularExpressions.Regex.Unescape("\\u" + string.Format("{0:X4}", (int)c).ToUpper()));
                result.AppendFormat("\\u{0:X4}", (int)c);
            }
            // Escape non-ASCII characters
            else if (c > 127)
            {
                var escaped = System.Text.RegularExpressions.Regex.Unescape("\\u" + string.Format("{0:X4}", (int)c).ToUpper());
                result.AppendFormat("\\u{0:X4}", (int)c);
            }
            else
            {
                result.Append(c);
            }
        }

        writer.WriteValue(result.ToString());
    }

    public override object ReadJson(JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
    {
        // For simplicity, just return the string as-is
        return reader.Value?.ToString();
    }
 }

Again there is difference in escaped values of System.Text.Json vs Newtonsoft.Json there is difference.
Output

{
  "Accents": "e.g. \u00A9, \u00AE, \u20AC, \u00A3, \u00A5, \u00B5.",
  "Scripts": "\u6F22 (Chinese), \u3053\u3093\u306B\u3061\u306F (Japanese), \u0627\u0644\u0633\u0644\u0627\u0645 \u0639\u0644\u064A\u0643\u0645 (Arabic).",
  "Symbols": "\u00A9, \u00AE, \u20AC, \u00A3, \u00A5, \u00B5.",
  "CJK": "\u6F22 (Chinese), \u3053\u3093\u306B\u3061\u306F (Japanese), \u0627\u0644\u0633\u0644\u0627\u0645 \u0639\u0644\u064A\u0643\u0645 (Arabic).",
  "CJKSymbols": "\u00A9, \u00AE, \u20AC, \u00A3, \u00A5, \u00B5.",
  "Emojis": "\uD83D\uDE00, \uD83D\uDC4D, \u2764\uFE0F. ",
  "NonAscii": "a  , o, u, \u00F1.",
  "HtmlSpecialCharacters": "\u003C, \u003E, \u0026, \u0027, \u0022)"
}
{
  "Accents": "e.g. \u00a9, \u00ae, \u20ac, \u00a3, \u00a5, \u00b5.",
  "Scripts": "\u6f22 (Chinese), \u3053\u3093\u306b\u3061\u306f (Japanese), \u0627\u0644\u0633\u0644\u0627\u0645 \u0639\u0644\u064a\u0643\u0645 (Arabic).",
  "Symbols": "\u00a9, \u00ae, \u20ac, \u00a3, \u00a5, \u00b5.",
  "CJK": "\u6f22 (Chinese), \u3053\u3093\u306b\u3061\u306f (Japanese), \u0627\u0644\u0633\u0644\u0627\u0645 \u0639\u0644\u064a\u0643\u0645 (Arabic).",
  "CJKSymbols": "\u00a9, \u00ae, \u20ac, \u00a3, \u00a5, \u00b5.",
  "Emojis": "\ud83d\ude00, \ud83d\udc4d, \u2764\ufe0f. ",
  "NonAscii": "a  , o, u, \u00f1.",
  "HtmlSpecialCharacters": "<, >, &, ', \")"
}
Accents  :True
CJK  :True
CJKSymbols  :True
Emojis  :True
HtmlSpecialCharacters  :True
NonAscii  :True
Symbols  :True
Scripts  :True
@tavisca-mjadhav commented on GitHub (Dec 11, 2025): > [@tavisca-mjadhav](https://github.com/tavisca-mjadhav) Did you try this? > > > It's already possible to provide the json serializer here: > > https://github.com/wiremock/WireMock.Net/blob/master/src/WireMock.Net.Minimal/ResponseBuilders/Response.WithBody.cs#L217 @StefH yes. I have already given it a try. The problem is, System.Text.Json by default handles & escapes NonAscii & Html characters. But in Newtonsoft.Json Since the StringEscapeHandling is not a [Flags] enum , I can only use either `StringEscapeHandling.EscapeNonAscii` or `StringEscapeHandling.EscapeHtml`, but not both. Not even custom converter supports this. Due to this, the Wiremock recorded files will either have escaped Html characters or escaped NonAscii characters but not both, which is again causing the HASH difference as mentioned in above comment. ``` c# //This is not supported var jsonSerializerSettings = new Newtonsoft.Json.JsonSerializerSettings { StringEscapeHandling = StringEscapeHandling.EscapeHtml | StringEscapeHandling.EscapeNonAscii, //NOT SUPPORTED Formatting = Formatting.Indented }; ``` ``` c# using System; using System.Text.Encodings.Web; using System.Text.Json; using System.Text.Unicode; using Newtonsoft.Json; public class Program { public static void Main() { Console.WriteLine(("\\u" + string.Format("{0:X4}", (int)127).ToUpper())); var options1 = new System.Text.Json.JsonSerializerOptions { WriteIndented = true }; var options2 = new Newtonsoft.Json.JsonSerializerSettings { StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Formatting = Formatting.Indented }; //options2.Converters.Add(new UppercaseUnicodeStringConverter()); var objec = new SpecialCharacters { Accents = "e.g. ©, ®, €, £, ¥, µ.", Scripts = "漢 (Chinese), こんにちは (Japanese), السلام عليكم (Arabic).", Symbols = "©, ®, €, £, ¥, µ.", CJK = "漢 (Chinese), こんにちは (Japanese), السلام عليكم (Arabic).", CJKSymbols = "©, ®, €, £, ¥, µ.", Emojis = "😀, 👍, ❤️. ", NonAscii = "a , o, u, ñ.", HtmlSpecialCharacters = "<, >, &, ', \")" }; var sysTextString = System.Text.Json.JsonSerializer.Serialize(objec, options1); Console.WriteLine(sysTextString); var nwtonString = Newtonsoft.Json.JsonConvert.SerializeObject(objec, options2); Console.WriteLine(nwtonString); var o1 = System.Text.Json.JsonSerializer.Deserialize<SpecialCharacters>(nwtonString); var o2 = Newtonsoft.Json.JsonConvert.DeserializeObject<SpecialCharacters>(sysTextString); Console.WriteLine("Accents :" + string.Equals(o1.Accents, o2.Accents)); Console.WriteLine("CJK :" + string.Equals(o1.CJK, o2.CJK)); Console.WriteLine("CJKSymbols :" + string.Equals(o1.CJKSymbols, o2.CJKSymbols)); Console.WriteLine("Emojis :" + string.Equals(o1.Emojis, o2.Emojis)); Console.WriteLine("HtmlSpecialCharacters :" + string.Equals(o1.HtmlSpecialCharacters, o2.HtmlSpecialCharacters)); Console.WriteLine("NonAscii :" + string.Equals(o1.NonAscii, o2.NonAscii)); Console.WriteLine("Symbols :" + string.Equals(o1.Symbols, o2.Symbols)); Console.WriteLine("Scripts :" + string.Equals(o1.Scripts, o2.Scripts)); } } public class SpecialCharacters { public string Accents { get; set; } public string Scripts { get; set; } public string Symbols { get; set; } public string CJK { get; set; } public string CJKSymbols { get; set; } public string Emojis { get; set; } public string NonAscii { get; set; } public string HtmlSpecialCharacters { get; set; } } public class UppercaseUnicodeStringConverter : Newtonsoft.Json.JsonConverter { // List of HTML special characters to escape private static readonly char[] HtmlSpecialChars = { '<', '>', '&', '\'', '"' }; public override bool CanConvert(Type objectType) { return objectType == typeof(string); } public override void WriteJson(JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) { string input = value as string; if (input == null) { writer.WriteNull(); return; } var result = new System.Text.StringBuilder(); foreach (char c in input) { // Escape HTML special characters if (Array.IndexOf(HtmlSpecialChars, c) >= 0) { // result.Append(System.Text.RegularExpressions.Regex.Unescape("\\u" + string.Format("{0:X4}", (int)c).ToUpper())); result.AppendFormat("\\u{0:X4}", (int)c); } // Escape non-ASCII characters else if (c > 127) { var escaped = System.Text.RegularExpressions.Regex.Unescape("\\u" + string.Format("{0:X4}", (int)c).ToUpper()); result.AppendFormat("\\u{0:X4}", (int)c); } else { result.Append(c); } } writer.WriteValue(result.ToString()); } public override object ReadJson(JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) { // For simplicity, just return the string as-is return reader.Value?.ToString(); } } ``` Again there is difference in escaped values of System.Text.Json vs Newtonsoft.Json there is difference. Output ``` json { "Accents": "e.g. \u00A9, \u00AE, \u20AC, \u00A3, \u00A5, \u00B5.", "Scripts": "\u6F22 (Chinese), \u3053\u3093\u306B\u3061\u306F (Japanese), \u0627\u0644\u0633\u0644\u0627\u0645 \u0639\u0644\u064A\u0643\u0645 (Arabic).", "Symbols": "\u00A9, \u00AE, \u20AC, \u00A3, \u00A5, \u00B5.", "CJK": "\u6F22 (Chinese), \u3053\u3093\u306B\u3061\u306F (Japanese), \u0627\u0644\u0633\u0644\u0627\u0645 \u0639\u0644\u064A\u0643\u0645 (Arabic).", "CJKSymbols": "\u00A9, \u00AE, \u20AC, \u00A3, \u00A5, \u00B5.", "Emojis": "\uD83D\uDE00, \uD83D\uDC4D, \u2764\uFE0F. ", "NonAscii": "a , o, u, \u00F1.", "HtmlSpecialCharacters": "\u003C, \u003E, \u0026, \u0027, \u0022)" } { "Accents": "e.g. \u00a9, \u00ae, \u20ac, \u00a3, \u00a5, \u00b5.", "Scripts": "\u6f22 (Chinese), \u3053\u3093\u306b\u3061\u306f (Japanese), \u0627\u0644\u0633\u0644\u0627\u0645 \u0639\u0644\u064a\u0643\u0645 (Arabic).", "Symbols": "\u00a9, \u00ae, \u20ac, \u00a3, \u00a5, \u00b5.", "CJK": "\u6f22 (Chinese), \u3053\u3093\u306b\u3061\u306f (Japanese), \u0627\u0644\u0633\u0644\u0627\u0645 \u0639\u0644\u064a\u0643\u0645 (Arabic).", "CJKSymbols": "\u00a9, \u00ae, \u20ac, \u00a3, \u00a5, \u00b5.", "Emojis": "\ud83d\ude00, \ud83d\udc4d, \u2764\ufe0f. ", "NonAscii": "a , o, u, \u00f1.", "HtmlSpecialCharacters": "<, >, &, ', \")" } Accents :True CJK :True CJKSymbols :True Emojis :True HtmlSpecialCharacters :True NonAscii :True Symbols :True Scripts :True ```
Author
Owner

@StefH commented on GitHub (Dec 12, 2025):

@tavisca-mjadhav
I see your point.

Maybe a solution for this would be that the proxy recording does not try to parse/write json, but just the string or just even the body as bytes.
Probably need to change te recording logic and add an setting for this.

@StefH commented on GitHub (Dec 12, 2025): @tavisca-mjadhav I see your point. ~Maybe a solution for this would be that the proxy recording does not try to parse/write json, but just the string or just even the body as bytes. Probably need to change te recording logic and add an setting for this.~
Author
Owner

@StefH commented on GitHub (Dec 15, 2025):

@tavisca-mjadhav
A better solution would be that the JSON (de)-serialization from the mapping files is configurable between newtonsoft and systemtext. I'll take a look.

@StefH commented on GitHub (Dec 15, 2025): @tavisca-mjadhav A better solution would be that the JSON (de)-serialization from the mapping files is configurable between newtonsoft and systemtext. I'll take a look.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#711