using XFEExtension.NetCore.Exceptions;
using XFEExtension.NetCore.XFETransform.Json;
namespace XFEExtension.NetCore.XFETransform;
///
/// 旧版 JSON 转换入口。新代码应使用 。
///
public static class XFEJsonTransformer
{
///
/// 将对象转换为 JSON 字符串。
///
[Obsolete("请使用 XFEJson.Serialize 或 ToJson。")]
public static string? ConvertToJson(this object? obj)
{
if (obj is null)
throw new XFEJsonTransformException("对象为空");
return XFEJson.Serialize(obj);
}
///
/// 将 JSON 字符串转换为对象。
///
[Obsolete("请使用 XFEJson.Deserialize 或 FromJson。")]
public static T ConvertFromJson(string jsonString)
{
if (string.IsNullOrEmpty(jsonString))
throw new ArgumentException("JSON 字符串为空。", nameof(jsonString));
return XFEJson.Deserialize(jsonString)!;
}
}