diff --git a/sdk/core/Azure.Core.TestFramework/src/RecordEntry.cs b/sdk/core/Azure.Core.TestFramework/src/RecordEntry.cs index 0484c8ce6f27..45130920ac25 100644 --- a/sdk/core/Azure.Core.TestFramework/src/RecordEntry.cs +++ b/sdk/core/Azure.Core.TestFramework/src/RecordEntry.cs @@ -188,8 +188,11 @@ private void SerializeBody(Utf8JsonWriter jsonWriter, string name, byte[] reques // We use array as a wrapper for string based serialization // so if the root is an array we can't write it directly - // fallback to generic string writing - if (document.RootElement.ValueKind != JsonValueKind.Array) + // fallback to generic string writing. Also, if the root is a string + // we don't want to write it directly, as this would make matching + // not won't work in libraries that allow passing JSON as a string. + if (document.RootElement.ValueKind != JsonValueKind.Array && + document.RootElement.ValueKind != JsonValueKind.String) { // Make sure we can replay JSON is exactly the same as the source // for the case where service response was pre-formatted diff --git a/sdk/core/Azure.Core/tests/RecordSessionTests.cs b/sdk/core/Azure.Core/tests/RecordSessionTests.cs index aba3efc5a458..adc10ec5c69c 100644 --- a/sdk/core/Azure.Core/tests/RecordSessionTests.cs +++ b/sdk/core/Azure.Core/tests/RecordSessionTests.cs @@ -23,6 +23,7 @@ public class RecordSessionTests [TestCase("{\"json\" :\"value\"}", "application/json")] [TestCase("[\"json\", \"value\"]", "application/json")] [TestCase("[{\"json\":\"value\"}, {\"json\":\"value\"}]", "application/json")] + [TestCase("\"\"", "application/json")] [TestCase("invalid json", "application/json")] [TestCase("{ \"json\": \"value\" }", "unknown")] [TestCase("multi\rline", "application/xml")]