< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Utilities.Json.JsonSerializerHelper
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Utilities/Json/JsonSerializerHelper.cs
Tag: Kestrun/Kestrun@ca54e35c77799b76774b3805b6f075cdbc0c5fbe
Line coverage
100%
Covered lines: 11
Uncovered lines: 0
Coverable lines: 11
Total lines: 41
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 12/12/2025 - 17:27:19 Line coverage: 0% (0/9) Branch coverage: 0% (0/2) Total lines: 35 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd01/15/2026 - 23:50:39 Line coverage: 100% (11/11) Branch coverage: 100% (4/4) Total lines: 41 Tag: Kestrun/Kestrun@2d823cb7ceae127151c8880ca073ffbb9c6322aa 12/12/2025 - 17:27:19 Line coverage: 0% (0/9) Branch coverage: 0% (0/2) Total lines: 35 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd01/15/2026 - 23:50:39 Line coverage: 100% (11/11) Branch coverage: 100% (4/4) Total lines: 41 Tag: Kestrun/Kestrun@2d823cb7ceae127151c8880ca073ffbb9c6322aa

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
FromJson(...)100%22100%
FromJson(...)100%22100%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Utilities/Json/JsonSerializerHelper.cs

#LineLine coverage
 1using System.Text.Json;
 2namespace Kestrun.Utilities.Json;
 3
 4/// <summary>
 5/// Helper class for JSON serialization and deserialization using System.Text.Json.
 6/// </summary>
 7public static class JsonSerializerHelper
 8{
 19    private static readonly JsonSerializerOptions Options = new()
 110    {
 111        PropertyNameCaseInsensitive = true,
 112        // If you want enums as strings etc, you can add converters here
 113        // Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
 114    };
 15
 16    /// <summary>
 17    /// Deserializes the given JSON string to an object of type T.
 18    /// </summary>
 19    /// <typeparam name="T"> The type of the object to deserialize to. </typeparam>
 20    /// <param name="json"> The JSON string to deserialize. </param>
 21    /// <returns> The deserialized object of type T. </returns>
 22    public static T FromJson<T>(string json)
 23    {
 324        var result = JsonSerializer.Deserialize<T>(json, Options);
 225        return result is null ? throw new JsonException($"Deserialization of type '{typeof(T)}' from JSON failed.") : re
 26    }
 27
 28    /// <summary>
 29    /// Deserializes the given JSON string to an object of the specified type.
 30    /// </summary>
 31    /// <param name="json"> The JSON string to deserialize. </param>
 32    /// <param name="type"> The type to which the JSON string should be deserialized. </param>
 33    /// <returns> The deserialized object. </returns>
 34    public static object FromJson(string json, Type type)
 35    {
 236        ArgumentNullException.ThrowIfNull(type);
 37
 238        var result = JsonSerializer.Deserialize(json, type, Options);
 239        return result is null ? throw new JsonException($"Deserialization of type '{type}' from JSON failed.") : result;
 40    }
 41}