< Summary

Information
Class: Elsa.Workflows.Serialization.Serializers.ApiSerializer
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Serialization/Serializers/ApiSerializer.cs
Line coverage
64%
Covered lines: 9
Uncovered lines: 5
Coverable lines: 14
Total lines: 53
Line coverage: 64.2%
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%11100%
Deserialize(...)100%210%
Deserialize(...)100%210%
Configure(...)100%11100%
AddConverters(...)100%11100%
Elsa.Workflows.IApiSerializer.GetOptions()100%11100%
Elsa.Workflows.IApiSerializer.ApplyOptions(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Serialization/Serializers/ApiSerializer.cs

#LineLine coverage
 1using System.Text.Json;
 2using Elsa.Common.Serialization;
 3using Elsa.Workflows.Serialization.Converters;
 4
 5namespace Elsa.Workflows.Serialization.Serializers;
 6
 7/// <inheritdoc cref="IApiSerializer" />
 8public class ApiSerializer : ConfigurableSerializer, IApiSerializer
 9{
 10    /// <summary>
 11    /// Initializes a new instance of the <see cref="ApiSerializer"/> class.
 12    /// </summary>
 13    public ApiSerializer(IServiceProvider serviceProvider)
 22814        : base(serviceProvider) { }
 15
 16    /// <inheritdoc />
 17    public string Serialize(object model)
 18    {
 1219        var options = GetOptions();
 1220        return JsonSerializer.Serialize(model, options);
 21    }
 22
 23    /// <inheritdoc />
 024    public object Deserialize(string serializedModel) => Deserialize<object>(serializedModel);
 25
 26    /// <inheritdoc />
 27    public T Deserialize<T>(string serializedModel)
 28    {
 029        var options = GetOptions();
 030        return JsonSerializer.Deserialize<T>(serializedModel, options)!;
 31    }
 32
 33    /// <inheritdoc />
 34    protected override void Configure(JsonSerializerOptions options)
 35    {
 136        options.PropertyNameCaseInsensitive = true;
 137    }
 38
 39    /// <inheritdoc />
 40    protected override void AddConverters(JsonSerializerOptions options)
 41    {
 142        options.Converters.Add(CreateInstance<TypeJsonConverter>());
 143        options.Converters.Add(CreateInstance<FuncExpressionValueConverter>());
 144    }
 45
 646    JsonSerializerOptions IApiSerializer.GetOptions() => GetOptions();
 47
 48    JsonSerializerOptions IApiSerializer.ApplyOptions(JsonSerializerOptions options)
 49    {
 050        ApplyOptions(options);
 051        return options;
 52    }
 53}