< 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@0d738bf294e6281b936d031e1979d928007495ff
Line coverage
0%
Covered lines: 0
Uncovered lines: 9
Coverable lines: 9
Total lines: 35
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
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@826bf9dcf9db118c5de4c78a3259bce9549f0dcd 12/12/2025 - 17:27:19 Line coverage: 0% (0/9) Branch coverage: 0% (0/2) Total lines: 35 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%210%
FromJson(...)0%620%
FromJson(...)100%210%

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{
 09    private static readonly JsonSerializerOptions Options = new()
 010    {
 011        PropertyNameCaseInsensitive = true,
 012        // If you want enums as strings etc, you can add converters here
 013        // Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
 014    };
 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    {
 024        var result = JsonSerializer.Deserialize<T>(json, Options);
 025        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>
 034    public static object FromJson(string json, Type type) => JsonSerializer.Deserialize(json, type, Options)!;
 35}