summary refs log tree commit diff
path: root/LibGit/Extensions/ObjectExtensions.cs
blob: 2cdeccddab435e448e4380bc37f04285efa3929a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
using System.Text.Json;

namespace LibGit.Extensions;

public static class ObjectExtensions
{
    public static string ToJson(this object obj, bool indent = true, bool ignoreNull = false, bool unsafeContent = false)
    {
        var jso = new JsonSerializerOptions();
        if(indent) jso.WriteIndented = true;
        if(ignoreNull) jso.IgnoreNullValues = true;
        if(unsafeContent) jso.Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping;
        return JsonSerializer.Serialize(obj, jso);
    }
}