#if !UNITY_5_3_OR_NEWER
using Newtonsoft.Json;
namespace Cobilas.IO.Serialization.Json {
#pragma warning disable CS1591 // O comentário XML ausente não foi encontrado para o tipo ou membro visível publicamente
public static class Json {
#pragma warning restore CS1591 // O comentário XML ausente não foi encontrado para o tipo ou membro visível publicamente
///
/// Serializes the specified object to a JSON string using .
///
/// The object to serialize.
/// The Newtonsoft.Json.JsonSerializerSettings used to serialize the object. If this
/// is null, default serialization settings will be used.
public static string Serialize(object value, JsonSerializerSettings settings)
=> JsonConvert.SerializeObject(value, settings);
///
/// Serializes the specified object to a JSON string using .
///
/// The object to serialize.
/// This parameter allows you to format the json file.
public static string Serialize(object value, bool Indented) {
JsonSerializerSettings resolver = new JsonSerializerSettings() {
ContractResolver = new JsonContractResolver(),
Formatting = Indented ? Formatting.Indented : Formatting.None
};
return Serialize(value, resolver);
}
///
/// Serializes the specified object to a JSON string using .
///
/// The object to serialize.
public static string Serialize(object value)
=> Serialize(value, true);
///
/// Deserializes the JSON to a .NET object using .
///
/// The JSON to deserialize.
/// The Newtonsoft.Json.JsonSerializerSettings used to deserialize the object. If
/// this is null, default serialization settings will be used.
public static object Deserialize(string value, JsonSerializerSettings settings)
=> JsonConvert.DeserializeObject(value, settings);
///
/// Deserializes the JSON to a .NET object using .
///
/// The JSON to deserialize.
public static object Deserialize(string value) {
JsonSerializerSettings resolver = new JsonSerializerSettings() {
ContractResolver = new JsonContractResolver()
};
return Deserialize(value, resolver);
}
///
/// Deserializes the JSON to a .NET object using .
///
/// The JSON to deserialize.
/// The Newtonsoft.Json.JsonSerializerSettings used to deserialize the object. If
/// this is null, default serialization settings will be used.
public static T Deserialize(string value, JsonSerializerSettings settings)
=> JsonConvert.DeserializeObject(value, settings);
///
/// Deserializes the JSON to a .NET object using .
///
/// The JSON to deserialize.
public static T Deserialize(string value) {
JsonSerializerSettings resolver = new JsonSerializerSettings() {
ContractResolver = new JsonContractResolver()
};
return Deserialize(value, resolver);
}
}
}
#endif