Skip to content

Commit

Permalink
Making json serialization and deserialization as extension methods
Browse files Browse the repository at this point in the history
  • Loading branch information
usa-m committed Jun 5, 2022
1 parent 1f2e0bd commit 5635c4c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/ACMEv2/Core/Extensions/JsonExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Text.Json;

namespace CronBlocks.ACMEv2.Core.Extensions
{
internal static class JsonExtensions
{
public static string SerializeToJson<T>(this T obj)
{
if (obj == null)
{
return null;
}

return JsonSerializer.Serialize(obj);
}

public static T DeserializeFromJson<T>(this string json)
{
if (string.IsNullOrEmpty(json))
{
return default(T);
}

return JsonSerializer.Deserialize<T>(json);
}
}
}

0 comments on commit 5635c4c

Please sign in to comment.