sharee.bike-App/TINKLib/Repository/Response/JsonConvertRethrow.cs

28 lines
892 B
C#
Raw Permalink Normal View History

2021-05-13 20:03:07 +02:00
using TINK.Repository.Exception;
namespace TINK.Repository.Response
{
2021-06-26 20:57:55 +02:00
public static class JsonConvertRethrow
2021-05-13 20:03:07 +02:00
{
/// <summary>
/// Deserializes COPRI responses in a consitent way for entire app.
/// </summary>
/// <typeparam name="T">Type of object to serialize to.</typeparam>
/// <param name="response">JSON to deserialize.</param>
/// <returns>Deserialized object.</returns>
public static T DeserializeObject<T>(string response)
{
try
{
return Newtonsoft.Json.JsonConvert.DeserializeObject<T>(response);
}
catch (System.Exception ex)
{
throw new DeserializationException(ex);
}
}
public static string SerializeObject(object value) => Newtonsoft.Json.JsonConvert.SerializeObject(value);
}
}