Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ability to serialize GUIDs #203

Merged
merged 1 commit into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sdk/src/Core/ThirdParty/LitJson/JsonMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,12 @@ private static void WriteValue (object obj, JsonWriter writer,
return;
}

if (obj is Guid)
{
writer.Write(obj.ToString());
return;
}

if (obj is Array) {
writer.WriteArrayStart ();

Expand Down
27 changes: 27 additions & 0 deletions sdk/test/UnitTests/JsonMapperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

using Amazon.XRay.Recorder.Core.Sampling.Model;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using ThirdParty.LitJson;

namespace Amazon.XRay.Recorder.UnitTests
Expand Down Expand Up @@ -271,5 +272,31 @@ public void TestUnmarshallSamplingTargetResponseWithNull()

Assert.IsNull(samplingTargetResponseModel);
}

[TestMethod]
public void SerializeObjectContainingEmptyGuid()
{
var obj = new AnythingWithGuid();
var actual = JsonMapper.ToJson(obj);
var expected = "{\"Id\":\"00000000-0000-0000-0000-000000000000\"}";

Assert.AreEqual(expected, actual);
}

[TestMethod]
public void SerializeObjectContainingNonEmptyGuid()
{
var guid = Guid.Parse("b2aee583-770c-42c5-b5d8-d25e0df4d161");
var obj = new AnythingWithGuid { Id = guid };
var actual = JsonMapper.ToJson(obj);
var expected = "{\"Id\":\"b2aee583-770c-42c5-b5d8-d25e0df4d161\"}";

Assert.AreEqual(expected, actual);
}

public class AnythingWithGuid
{
public Guid Id { get; set; }
}
}
}