using Swifter.Json; using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Threading.Tasks; namespace Core.RabbitMQBus.EventBus { public class SwifterJsonSerializer : ISerializer { /// /// 将指定类型的实例序列化为string /// /// /// public static string SerializeObject(object value) { var strValue = JsonFormatter.SerializeObject(value); return strValue; } /// /// 将指定类型的实例序列化为Byte[] /// /// /// public static byte[] SerializeObjectToByte(object value) { var strValue = JsonFormatter.SerializeObject(value); return Encoding.Default.GetBytes(strValue); } /// /// 将 Json 字符串反序列化为指定类型的实例 /// /// /// /// public static T DeserializeObject(string value) { return JsonFormatter.DeserializeObject(value); } /// /// 根据类型解析json /// /// /// public static object DeserializeObject(string value, Type type) { var obj = JsonFormatter.DeserializeObject(value, type); return obj; } } }