using System.Text.Json;
using System.Text.Json.Serialization;

namespace ExtensionMethods {
  public static class ObjectExtensions {

    /// <summary>
    /// Converts object to json string
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="obj"></param>
    /// <returns></returns>
    public static string ToJson<T>(this T obj) {
      return JsonSerializer.Serialize(obj, new JsonSerializerOptions {
        PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
        DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
      });
    }
  }
}