< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 21
Coverable lines: 21
Total lines: 52
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
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(...)0%440%
ReadNonNullPrimitiveValue(...)0%220%
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)
 024        {
 025            if (reader.TokenType is JsonTokenType.Null)
 026            {
 027                return null;
 28            }
 29
 030            switch (reader.TokenType)
 31            {
 32                case JsonTokenType.String:
 33                case JsonTokenType.False:
 34                case JsonTokenType.True:
 35                case JsonTokenType.Number:
 036                    return ReadNonNullPrimitiveValue(ref reader, options.GetNodeOptions());
 37                default:
 038                    JsonElement element = JsonElement.ParseValue(ref reader, options.AllowDuplicateProperties);
 039                    return JsonValue.CreateFromElement(ref element, options.GetNodeOptions());
 40            }
 041        }
 42
 43        internal static JsonValue ReadNonNullPrimitiveValue(ref Utf8JsonReader reader, JsonNodeOptions options)
 044        {
 045            Debug.Assert(reader.TokenType is JsonTokenType.String or JsonTokenType.False or JsonTokenType.True or JsonTo
 046            return JsonValueOfJsonPrimitive.CreatePrimitiveValue(ref reader, options);
 047        }
 48
 049        internal override JsonSchema? GetSchema(JsonNumberHandling _) => JsonSchema.CreateTrueSchema();
 50    }
 51}
 52