< Summary

Information
Line coverage
10%
Covered lines: 3
Uncovered lines: 25
Coverable lines: 28
Total lines: 55
Line coverage: 10.7%
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
Read(...)100%11100%
Write(...)0%220%
ReadAsPropertyNameCore(...)100%110%
WriteAsPropertyNameCore(...)0%660%
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\Value\StringConverter.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 StringConverter : JsonPrimitiveConverter<string?>
 11    {
 12        public override string? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
 66013        {
 66014            return reader.GetString();
 18015        }
 16
 17        public override void Write(Utf8JsonWriter writer, string? value, JsonSerializerOptions options)
 018        {
 19            // For performance, lift up the writer implementation.
 020            if (value == null)
 021            {
 022                writer.WriteNullValue();
 023            }
 24            else
 025            {
 026                writer.WriteStringValue(value.AsSpan());
 027            }
 028        }
 29
 30        internal override string ReadAsPropertyNameCore(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOpt
 031        {
 032            Debug.Assert(reader.TokenType == JsonTokenType.PropertyName);
 033            return reader.GetString()!;
 034        }
 35
 36        internal override void WriteAsPropertyNameCore(Utf8JsonWriter writer, string value, JsonSerializerOptions option
 037        {
 038            ArgumentNullException.ThrowIfNull(value);
 39
 040            if (options.DictionaryKeyPolicy != null && !isWritingExtensionDataProperty)
 041            {
 042                value = options.DictionaryKeyPolicy.ConvertName(value);
 43
 044                if (value == null)
 045                {
 046                    ThrowHelper.ThrowInvalidOperationException_NamingPolicyReturnNull(options.DictionaryKeyPolicy);
 47                }
 048            }
 49
 050            writer.WritePropertyName(value);
 051        }
 52
 053        internal override JsonSchema? GetSchema(JsonNumberHandling _) => new() { Type = JsonSchemaType.String };
 54    }
 55}