Skip to content

Commit

Permalink
dont ignore json refs (#1170)
Browse files Browse the repository at this point in the history
* dont ignore json refs

* Create SerializationTests.Ref.verified.json
  • Loading branch information
SimonCropp authored Mar 27, 2024
1 parent 9f8743c commit fa5103f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/StrictJsonTests/SerializationTests.Ref.verified.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"a": {
"$id": "x",
"b": 1
},
"b": 2,
"c": {
"$ref": "#x/b"
},
"d": {
"$ref": "#/b"
}
}
13 changes: 13 additions & 0 deletions src/Verify.Tests/Serialization/SerializationTests.Ref.verified.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
a: {
$id: x,
b: 1
},
b: 2,
c: {
$ref: #x/b
},
d: {
$ref: #/b
}
}
7 changes: 7 additions & 0 deletions src/Verify.Tests/Serialization/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3895,6 +3895,13 @@ public class Child
public Parent Parent { get; set; }
}

[Fact]
public Task Ref()
{
var json = """{ "a": { "$id": "x", "b": 1 }, "b": 2, "c": { "$ref": "#x/b" }, "d": { "$ref": "#/b" } }""";
return VerifyJson(json);
}

[Fact]
public async Task CancellationToken_Cancelled()
{
Expand Down
16 changes: 12 additions & 4 deletions src/Verify/Serialization/Converters/JObjectConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@ public override void Write(VerifyJsonWriter writer, JObject value)
{
if (VerifierSettings.sortJsonObjects)
{
var dictionary = value
.ToObject<Dictionary<string, object>>(writer.Serializer)!;
var dictionary = new Dictionary<string, object?>();
foreach (var item in value)
{
dictionary.Add(item.Key, item.Value);
}

writer.Serialize(dictionary);
}
else
{
var dictionary = value
.ToObject<OrderedDictionary>(writer.Serializer)!;
var dictionary = new OrderedDictionary();
foreach (var item in value)
{
dictionary.Add(item.Key, item.Value);
}

writer.Serialize(dictionary);
}
}
Expand Down

0 comments on commit fa5103f

Please sign in to comment.