< Summary

Information
Class: Elsa.Common.Converters.IntegerJsonConverter
Assembly: Elsa.Common
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/Converters/IntegerJsonConverter.cs
Line coverage
50%
Covered lines: 4
Uncovered lines: 4
Coverable lines: 8
Total lines: 33
Line coverage: 50%
Branch coverage
25%
Covered branches: 1
Total branches: 4
Branch coverage: 25%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Read(...)25%9433.33%
Write(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/Converters/IntegerJsonConverter.cs

#LineLine coverage
 1using System.Globalization;
 2using System.Text.Json;
 3using System.Text.Json.Serialization;
 4
 5namespace Elsa.Common.Converters;
 6
 7/// <summary>
 8/// Converts integers to and from JSON strings.
 9/// </summary>
 10public class IntegerJsonConverter : JsonConverter<int>
 11{
 12    /// <inheritdoc />
 13    public override int Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
 14    {
 336015        if (reader.TokenType == JsonTokenType.Number)
 336016            return reader.GetInt32();
 17
 018        if (reader.TokenType == JsonTokenType.String)
 19        {
 020            var value = reader.GetString()!;
 021            return int.Parse(value, CultureInfo.InvariantCulture);
 22        }
 23
 024        throw new JsonException("Expected number or string.");
 25    }
 26
 27    /// <inheritdoc />
 28    public override void Write(Utf8JsonWriter writer, int value, JsonSerializerOptions options)
 29    {
 30        // Write the integer as a JSON number.
 271831        writer.WriteNumberValue(value);
 271832    }
 33}