< Summary

Information
Class: Elsa.Common.Serialization.StandardJsonSerializer
Assembly: Elsa.Common
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/Serialization/JsonSerializer.cs
Line coverage
16%
Covered lines: 2
Uncovered lines: 10
Coverable lines: 12
Total lines: 59
Line coverage: 16.6%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Serialize(...)100%210%
Serialize(...)100%210%
Serialize(...)100%210%
Deserialize(...)100%210%
Deserialize(...)100%210%
Deserialize(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/Serialization/JsonSerializer.cs

#LineLine coverage
 1using System.Diagnostics.CodeAnalysis;
 2using System.Text.Json;
 3
 4namespace Elsa.Common.Serialization;
 5
 6/// <summary>
 7/// Provides JSON serialization services.
 8/// </summary>
 9public class StandardJsonSerializer : ConfigurableSerializer, IJsonSerializer
 10{
 11    /// <inheritdoc />
 112    public StandardJsonSerializer(IServiceProvider serviceProvider) : base(serviceProvider)
 13    {
 114    }
 15
 16    /// <inheritdoc />
 17    [RequiresUnreferencedCode("The type is not known at compile time.")]
 18    public string Serialize(object value)
 19    {
 020        var options = GetOptions();
 021        return JsonSerializer.Serialize(value, options);
 22    }
 23
 24    /// <inheritdoc />
 25    [RequiresUnreferencedCode("The type is not known at compile time.")]
 26    public string Serialize(object? value, Type type)
 27    {
 028        var options = GetOptions();
 029        return JsonSerializer.Serialize(value, type, options);
 30    }
 31
 32    /// <inheritdoc />
 33    public string Serialize<T>(T value)
 34    {
 035        return Serialize(value, typeof(T));
 36    }
 37
 38    /// <inheritdoc />
 39    [RequiresUnreferencedCode("The type is not known at compile time.")]
 40    public object Deserialize(string json)
 41    {
 042        var options = GetOptions();
 043        return JsonSerializer.Deserialize<object>(json, options)!;
 44    }
 45
 46    /// <inheritdoc />
 47    [RequiresUnreferencedCode("The type is not known at compile time.")]
 48    public object Deserialize(string json, Type type)
 49    {
 050        var options = GetOptions();
 051        return JsonSerializer.Deserialize(json, type, options)!;
 52    }
 53
 54    /// <inheritdoc />
 55    public T Deserialize<T>(string json)
 56    {
 057        return (T)Deserialize(json, typeof(T));
 58    }
 59}