ExternalAPI_NET8/Common/Helper/SerializeHelper.cs
2026-05-21 17:23:36 +08:00

33 lines
762 B
C#

#region
using System.Text;
using System.Text.Json;
#endregion
namespace Web.Core.Common.Helper;
public class SerializeHelper
{
/// <summary>
/// 序列化
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
public static byte[] Serialize(object item)
{
return item == null ? null : JsonSerializer.SerializeToUtf8Bytes(item);
}
/// <summary>
/// 反序列化
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="value"></param>
/// <returns></returns>
public static T Deserialize<T>(byte[] value)
{
var jsonString = Encoding.UTF8.GetString(value);
return value == null ? default : JsonSerializer.Deserialize<T>(value);
}
}