Skip to content

Commit

Permalink
Null String being reported as String rather than JTokenType.Null Jame…
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Feb 11, 2023
1 parent 828fcc3 commit 0f3b5b3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Argon/Linq/JTokenWriter.cs
Expand Up @@ -215,6 +215,12 @@ public override void WriteComment(string? text)
/// </summary>
public override void WriteValue(string? value)
{
if (value == null)
{
WriteNull();
return;
}

base.WriteValue(value);
AddJValue(new(value));
}
Expand Down
28 changes: 28 additions & 0 deletions src/Tests/Issues/Issue2775.cs
@@ -0,0 +1,28 @@
 public class Issue2775
{
[Fact]
//https://github.com/JamesNK/Newtonsoft.Json/issues/2775
public void TokenType()
{
var jObject = new JObject
{
{
"NullProperty", false ? "0" : null
}
};

var jToken = JToken.FromObject(jObject);

Assert.Equal(JTokenType.Null, jToken.Children().Children().Single().Type);

jObject = new()
{
{
"NullProperty", (string) null
}
};

jToken = JToken.FromObject(jObject);
Assert.Equal(JTokenType.Null, jToken.Children().Children().Single().Type);
}
}

0 comments on commit 0f3b5b3

Please sign in to comment.