< Summary

Information
Class: Elsa.Workflows.Serialization.Serializers.BookmarkPayloadSerializer
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Serialization/Serializers/BookmarkPayloadSerializer.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 13
Coverable lines: 13
Total lines: 38
Line coverage: 0%
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%210%
Deserialize(...)100%210%
Deserialize(...)100%210%
Serialize(...)100%210%

File(s)

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

#LineLine coverage
 1using System.Text.Json;
 2using Elsa.Expressions.Contracts;
 3using Elsa.Workflows.Serialization.Converters;
 4
 5namespace Elsa.Workflows.Serialization.Serializers;
 6
 7/// <inheritdoc />
 8public class BookmarkPayloadSerializer : IBookmarkPayloadSerializer
 9{
 10    private readonly JsonSerializerOptions _settings;
 11
 12    /// <summary>
 13    /// Initializes a new instance of the <see cref="BookmarkPayloadSerializer"/> class.
 14    /// </summary>
 015    public BookmarkPayloadSerializer(IWellKnownTypeRegistry wellKnownTypeRegistry)
 16    {
 017        _settings = new JsonSerializerOptions
 018        {
 019            // Enables serialization of ValueTuples, which use fields instead of properties.
 020            IncludeFields = true,
 021            PropertyNameCaseInsensitive = true,
 022        };
 23
 024        _settings.Converters.Add(new TypeJsonConverter(wellKnownTypeRegistry));
 025        _settings.Converters.Add(new FuncExpressionValueConverter());
 026    }
 27
 28    /// <inheritdoc />
 29    public T Deserialize<T>(string json)
 030        where T : notnull => JsonSerializer.Deserialize<T>(json, _settings)!;
 31
 32    /// <inheritdoc />
 033    public object Deserialize(string json, Type type) => JsonSerializer.Deserialize(json, type, _settings)!;
 34
 35    /// <inheritdoc />
 36    public string Serialize<T>(T payload)
 037        where T : notnull => JsonSerializer.Serialize(payload, payload.GetType(), _settings);
 38}