Distribution_GL Initialization
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
using System.Text.Json;
|
||||
using General_Ledger_Service.Exceptions;
|
||||
|
||||
namespace General_Ledger_Service.Helpers
|
||||
{
|
||||
public static class DeserializePayload
|
||||
{
|
||||
public static Dictionary<string, JsonElement> Deserialize(object payload)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(payload);
|
||||
var json = JsonSerializer.Serialize(payload);
|
||||
return JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(json)
|
||||
?? throw new BadRequestException("Failed to deserialize payload.");
|
||||
}
|
||||
|
||||
public static T? DeserializeJson<T>(string? json) where T : class
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(json))
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
return JsonSerializer.Deserialize<T>(json);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user