< Summary

Information
Class: Elsa.Common.Services.JsonFormatter
Assembly: Elsa.Common
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/Services/JsonFormatter.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 8
Coverable lines: 8
Total lines: 30
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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%210%
ToStringAsync(...)100%210%
FromStringAsync(...)0%620%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/Services/JsonFormatter.cs

#LineLine coverage
 1using System.Text.Json;
 2using System.Text.Json.Serialization;
 3
 4namespace Elsa.Common.Services;
 5
 6/// <inheritdoc />
 7public class JsonFormatter : IFormatter
 8{
 9    private readonly JsonSerializerOptions _options;
 10
 011    public JsonFormatter()
 12    {
 013        _options = new JsonSerializerOptions();
 014        _options.Converters.Add(new JsonStringEnumConverter());
 015    }
 16
 17    /// <inheritdoc />
 18    public ValueTask<string> ToStringAsync(object value, CancellationToken cancellationToken = default)
 19    {
 020        var json = JsonSerializer.Serialize(value);
 021        return ValueTask.FromResult(json);
 22    }
 23
 24    /// <inheritdoc />
 25    public ValueTask<object> FromStringAsync(string data, Type? returnType, CancellationToken cancellationToken = defaul
 26    {
 027        var value = returnType != null ? JsonSerializer.Deserialize(data, returnType, _options)! : JsonSerializer.Deseri
 028        return ValueTask.FromResult(value);
 29    }
 30}