using System.Text.Json;

namespace Atomx.Utils.Json
{
    public static class JsonSerialize
	{
		public static string ToJson(this object obj, JsonSerializerOptions? options = null)
		{
			var opts = JsonOptions.DefaultOptions();
			if (options != null)
			{
				opts = options;
			}
			var data = JsonSerializer.Serialize(obj, opts);
			return data;
		}

		public static T? FromJson<T>(this string json, JsonSerializerOptions? options = null)
		{
			var opts = JsonOptions.DefaultOptions();
			if (options != null)
			{
				opts = options;
			}

			var data = JsonSerializer.Deserialize<T>(json, opts);
			return data;
		}
	}
}
