< Summary

Information
Line coverage
52%
Covered lines: 11
Uncovered lines: 10
Coverable lines: 21
Total lines: 51
Line coverage: 52.3%
Branch coverage
50%
Covered branches: 4
Total branches: 8
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
Write(...)0%220%
Read(...)75%4477.77%
ReadNonNullPrimitiveValue(...)50%22100%
GetSchema(...)100%110%

File(s)

C:\h\w\B31A098C\w\BB5A0A33\e\runtime-utils\Runner\runtime\src\libraries\System.Text.Json\src\System\Text\Json\Serialization\Converters\Node\JsonValueConverter.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Diagnostics;
 5using System.Text.Json.Nodes;
 6using System.Text.Json.Schema;
 7
 8namespace System.Text.Json.Serialization.Converters
 9{
 10    internal sealed class JsonValueConverter : JsonConverter<JsonValue?>
 11    {
 12        public override void Write(Utf8JsonWriter writer, JsonValue? value, JsonSerializerOptions options)
 013        {
 014            if (value is null)
 015            {
 016                writer.WriteNullValue();
 017                return;
 18            }
 19
 020            value.WriteTo(writer, options);
 021        }
 22
 23        public override JsonValue? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
 63424        {
 63425            if (reader.TokenType is JsonTokenType.Null)
 026            {
 027                return null;
 28            }
 29
 63430            switch (reader.TokenType)
 31            {
 32                case JsonTokenType.String:
 33                case JsonTokenType.False:
 34                case JsonTokenType.True:
 35                case JsonTokenType.Number:
 40636                    return ReadNonNullPrimitiveValue(ref reader, options.GetNodeOptions());
 37                default:
 22838                    JsonElement element = JsonElement.ParseValue(ref reader, options.AllowDuplicateProperties);
 2239                    return JsonValue.CreateFromElement(ref element, options.GetNodeOptions());
 40            }
 30441        }
 42
 43        internal static JsonValue ReadNonNullPrimitiveValue(ref Utf8JsonReader reader, JsonNodeOptions options)
 81244        {
 81245            Debug.Assert(reader.TokenType is JsonTokenType.String or JsonTokenType.False or JsonTokenType.True or JsonTo
 81246            return JsonValueOfJsonPrimitive.CreatePrimitiveValue(ref reader, options);
 60847        }
 48
 049        internal override JsonSchema? GetSchema(JsonNumberHandling _) => JsonSchema.CreateTrueSchema();
 50    }
 51}