< Summary

Information
Class: Elsa.Http.ContentWriters.JsonContentFactory
Assembly: Elsa.Http
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/ContentWriters/JsonContentFactory.cs
Line coverage
83%
Covered lines: 5
Uncovered lines: 1
Coverable lines: 6
Total lines: 29
Line coverage: 83.3%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_SupportedContentTypes()100%11100%
.cctor()100%11100%
CreateHttpContent(...)75%4475%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/ContentWriters/JsonContentFactory.cs

#LineLine coverage
 1using System.Diagnostics.CodeAnalysis;
 2using System.Net.Mime;
 3using System.Text;
 4using System.Text.Json;
 5
 6namespace Elsa.Http.ContentWriters;
 7
 8/// <summary>
 9/// Creates a <see cref="HttpContent"/> object for application/json.
 10/// </summary>
 11public class JsonContentFactory : IHttpContentFactory
 12{
 13    /// <inheritdoc />
 4514    public IEnumerable<string> SupportedContentTypes => [MediaTypeNames.Application.Json, "text/json"];
 15
 216    private static readonly UTF8Encoding _utf8Encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);
 17
 18    /// <inheritdoc />
 19    [RequiresUnreferencedCode("The JsonSerializer type is not trim-compatible.")]
 20    public HttpContent CreateHttpContent(object content, string contentType)
 21    {
 522        var text = content as string ?? JsonSerializer.Serialize(content);
 23
 524        if (string.IsNullOrWhiteSpace(contentType))
 025            contentType = MediaTypeNames.Application.Json;
 26
 527        return new RawStringContent(text, _utf8Encoding, contentType);
 28    }
 29}