< Summary

Line coverage
47%
Covered lines: 10
Uncovered lines: 11
Coverable lines: 21
Total lines: 52
Line coverage: 47.6%
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%4466.66%
ReadNonNullPrimitiveValue(...)50%22100%
GetSchema(...)100%110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/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)
 1224        {
 1225            if (reader.TokenType is JsonTokenType.Null)
 026            {
 027                return null;
 28            }
 29
 1230            switch (reader.TokenType)
 31            {
 32                case JsonTokenType.String:
 33                case JsonTokenType.False:
 34                case JsonTokenType.True:
 35                case JsonTokenType.Number:
 436                    return ReadNonNullPrimitiveValue(ref reader, options.GetNodeOptions());
 37                default:
 838                    JsonElement element = JsonElement.ParseValue(ref reader, options.AllowDuplicateProperties);
 039                    return JsonValue.CreateFromElement(ref element, options.GetNodeOptions());
 40            }
 441        }
 42
 43        internal static JsonValue ReadNonNullPrimitiveValue(ref Utf8JsonReader reader, JsonNodeOptions options)
 844        {
 845            Debug.Assert(reader.TokenType is JsonTokenType.String or JsonTokenType.False or JsonTokenType.True or JsonTo
 846            return JsonValueOfJsonPrimitive.CreatePrimitiveValue(ref reader, options);
 847        }
 48
 049        internal override JsonSchema? GetSchema(JsonNumberHandling _) => JsonSchema.CreateTrueSchema();
 50    }
 51}
 52