return ObjectConverter.Read(ref reader, typeToConvert, options);
case JsonTokenType.StartArray:
return ArrayConverter.Read(ref reader, typeToConvert, options);
+ case JsonTokenType.Null:
+ return null;
default:
Debug.Assert(false);
throw new JsonException();
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System.Collections;
+using System.Collections.Generic;
using Xunit;
namespace System.Text.Json.Nodes.Tests
Assert.IsAssignableFrom<JsonValue>(JsonNode.Parse("\"str\""));
Assert.IsAssignableFrom<JsonValue>(JsonNode.Parse(ToUtf8("\"str\"")));
Assert.IsType<JsonElement>(JsonSerializer.Deserialize<object>("\"str\""));
+
+ JsonType_Deserializes_Null<JsonNode>();
+ JsonType_Deserializes_Null<JsonArray>();
+ JsonType_Deserializes_Null<JsonObject>();
+ }
+
+ private static void JsonType_Deserializes_Null<TNode>() where TNode : JsonNode
+ {
+ Assert.Null(JsonSerializer.Deserialize<TNode>("null"));
+ Assert.Collection(JsonSerializer.Deserialize<TNode[]>("[null]"), Assert.Null);
+ Assert.Collection(JsonSerializer.Deserialize<IReadOnlyDictionary<string, TNode>>("{ \"Value\": null }"), kv => Assert.Null(kv.Value));
+ Assert.Null(JsonSerializer.Deserialize<ObjectWithNodeProperty<TNode>>("{ \"Value\": null }").Value);
}
+ private record ObjectWithNodeProperty<TNode>(TNode Value) where TNode : JsonNode;
[Fact]
public static void AsMethods_Throws()