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

30 lines
834 B
C#
Raw Permalink Normal View History

2024-04-09 12:53:23 +02:00
using Serilog;
using ShareeBike.Repository.Exception;
2021-05-13 20:03:07 +02:00
2024-04-09 12:53:23 +02:00
namespace ShareeBike.Repository.Response
2021-05-13 20:03:07 +02:00
{
2022-09-06 16:08:19 +02:00
public static class JsonConvertRethrow
{
/// <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)
{
2024-04-09 12:53:23 +02:00
Log.Error("Deserializing response failed. {@Exception}",ex);
2022-09-06 16:08:19 +02:00
throw new DeserializationException(ex);
}
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
public static string SerializeObject(object value) => Newtonsoft.Json.JsonConvert.SerializeObject(value);
}
2021-05-13 20:03:07 +02:00
}