using System.Diagnostics.CodeAnalysis;
using System.Net.Mime;
using System.Text;
using System.Text.Json;
namespace Elsa.Http.ContentWriters;
///
/// Creates a object for application/json.
///
public class JsonContentFactory : IHttpContentFactory
{
///
public IEnumerable SupportedContentTypes => new[] { MediaTypeNames.Application.Json, "text/json" };
///
[RequiresUnreferencedCode("The JsonSerializer type is not trim-compatible.")]
public HttpContent CreateHttpContent(object content, string contentType)
{
var text = content as string ?? JsonSerializer.Serialize(content);
if (string.IsNullOrWhiteSpace(contentType))
contentType = MediaTypeNames.Application.Json;
return new StringContent(text, Encoding.UTF8, contentType);
}
}