public static string ToJson <T>(T target, bool readable = false) { ISerializeUtf8JsonModule module = SerializeUtf8JsonModule; ISerializer <string> serializer = GetSerializer(module, readable); return(serializer.Serialize(target)); }
private static ISerializer <string> GetSerializer(ISerializeUtf8JsonModule module, bool readable) { string name = readable ? module.SerializeModule.Description.DefaultTextReadableSerializerName : module.SerializeModule.Description.DefaultTextCompactSerializerName; return(module.SerializeModule.Provider.Get <string>(name)); }
public static T FromJson <T>(string text) { if (string.IsNullOrEmpty(text)) { throw new ArgumentException("Value cannot be null or empty.", nameof(text)); } ISerializeUtf8JsonModule module = SerializeUtf8JsonModule; ISerializer <string> serializer = GetSerializer(module, false); return(serializer.Deserialize <T>(text)); }
public static string ToJson(object target, bool readable = false) { if (target == null) { throw new ArgumentNullException(nameof(target)); } ISerializeUtf8JsonModule module = SerializeUtf8JsonModule; ISerializer <string> serializer = GetSerializer(module, readable); return(serializer.Serialize(target)); }
public static object FromJson(string text, Type targetType) { if (string.IsNullOrEmpty(text)) { throw new ArgumentException("Value cannot be null or empty.", nameof(text)); } if (targetType == null) { throw new ArgumentNullException(nameof(targetType)); } ISerializeUtf8JsonModule module = SerializeUtf8JsonModule; ISerializer <string> serializer = GetSerializer(module, false); return(serializer.Deserialize(targetType, text)); }