Skip to content

Commit 7163a1a

Browse files
authored
Json serialization (#104)
* Wrap JSON serialization in try/catch
1 parent 273e98a commit 7163a1a

File tree

1 file changed

+10
-1
lines changed
  • IntelliTect.TestTools.TestFramework/IntelliTect.TestTools.TestFramework

1 file changed

+10
-1
lines changed

IntelliTect.TestTools.TestFramework/IntelliTect.TestTools.TestFramework/TestBuilder.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,16 @@ public void ExecuteTestCase()
196196

197197
private static string GetObjectDataAsJsonString(object obj)
198198
{
199-
return JsonSerializer.Serialize(obj, new JsonSerializerOptions { WriteIndented = true });
199+
200+
try
201+
{
202+
return JsonSerializer.Serialize(obj, new JsonSerializerOptions { WriteIndented = true });
203+
}
204+
catch (JsonException e)
205+
{
206+
return $"Unable to serialize object {obj?.GetType()} to JSON. Mark the relevant property with the [JsonIgnore] attribute: {e.Message}";
207+
}
208+
200209
}
201210

202211
private object GetTestBlock(IServiceScope scope, Type tbType)

0 commit comments

Comments
 (0)