File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
Newtonsoft.Json.Tests/Issues Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ using System . Linq ;
2
+ using Newtonsoft . Json . Linq ;
3
+ #if DNXCORE50
4
+ using Xunit ;
5
+ using Test = Xunit . FactAttribute ;
6
+ using Assert = Newtonsoft . Json . Tests . XUnitAssert ;
7
+ using TestCase = Xunit . InlineDataAttribute ;
8
+ #else
9
+ using NUnit . Framework ;
10
+ #endif
11
+
12
+ namespace Newtonsoft . Json . Tests . Issues
13
+ {
14
+ public class Issue2775
15
+ {
16
+ [ Test ]
17
+ //https://github.com/JamesNK/Newtonsoft.Json/issues/2775
18
+ public void TokenType ( )
19
+ {
20
+ var jObject = new JObject { { "NullProperty" , false ? "0" : null } } ;
21
+
22
+ var jToken = JToken . FromObject ( jObject ) ;
23
+
24
+ Assert . AreEqual ( JTokenType . Null , jToken . Children ( ) . Children ( ) . Single ( ) . Type ) ;
25
+
26
+ jObject = new JObject { { "NullProperty" , ( string ) null } } ;
27
+
28
+ jToken = JToken . FromObject ( jObject ) ;
29
+ Assert . AreEqual ( JTokenType . Null , jToken . Children ( ) . Children ( ) . Single ( ) . Type ) ;
30
+ }
31
+ }
32
+ }
Original file line number Diff line number Diff line change @@ -281,6 +281,12 @@ public override void WriteComment(string? text)
281
281
/// <param name="value">The <see cref="String"/> value to write.</param>
282
282
public override void WriteValue ( string ? value )
283
283
{
284
+ if ( value == null )
285
+ {
286
+ WriteNull ( ) ;
287
+ return ;
288
+ }
289
+
284
290
base . WriteValue ( value ) ;
285
291
AddJValue ( new JValue ( value ) , JsonToken . String ) ;
286
292
}
You can’t perform that action at this time.
0 commit comments