Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5a1572e

Browse filesBrowse files
committed
Fix for null string values
1 parent dfcfaf3 commit 5a1572e
Copy full SHA for 5a1572e

File tree

1 file changed

+20
-4
lines changed
Filter options

1 file changed

+20
-4
lines changed

‎Tests/Schema.NET.Test/ValuesJsonConverterTest.cs

Copy file name to clipboardExpand all lines: Tests/Schema.NET.Test/ValuesJsonConverterTest.cs
+20-4Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ public void WriteJson_Values_ZeroCountWritesNull()
1515
Assert.Equal("{}", json);
1616
}
1717

18+
[Fact]
19+
public void WriteJson_ValuesNull_WritesNull()
20+
{
21+
var value = new Values<int?, string?>((string?)null);
22+
var json = SerializeObject(value);
23+
Assert.Equal("{}", json);
24+
}
25+
1826
[Fact]
1927
public void WriteJson_Values_OneCountWritesSingle()
2028
{
@@ -87,6 +95,14 @@ public void WriteJson_TimeSpan_ISO8601_TimeOfDay()
8795
Assert.Equal("{\"Property\":\"12:34:56\"}", json);
8896
}
8997

98+
[Fact]
99+
public void ReadJson_Values_NullValue_String()
100+
{
101+
var json = "{\"Property\":null}";
102+
var result = DeserializeObject<Values<int, string?>>(json);
103+
Assert.Null(result.Value2.First());
104+
}
105+
90106
[Fact]
91107
public void ReadJson_Values_SingleValue_String()
92108
{
@@ -564,12 +580,12 @@ public void ReadJson_ImplicitExternalTypes_AllowSharedNamespace()
564580
}
565581

566582
private static string SerializeObject<T>(T value)
567-
where T : struct, IValues
568-
=> SchemaSerializer.SerializeObject(new TestModel<T> { Property = value });
583+
where T : struct, IValues =>
584+
SchemaSerializer.SerializeObject(new TestModel<T> { Property = value });
569585

570586
private static T DeserializeObject<T>(string json)
571-
where T : struct, IValues
572-
=> SchemaSerializer.DeserializeObject<TestModel<T>>(json)!.Property;
587+
where T : struct, IValues =>
588+
SchemaSerializer.DeserializeObject<TestModel<T>>(json)!.Property;
573589

574590
private class TestModel<T>
575591
where T : struct, IValues

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.