You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
754 B
30 lines
754 B
using System.IO.Abstractions;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Serialization;
|
|
|
|
namespace Recyclarr.TrashLib.Repo;
|
|
|
|
public static class TrashRepoJsonParser
|
|
{
|
|
public static T Deserialize<T>(IFileInfo jsonFile)
|
|
{
|
|
var serializer = JsonSerializer.Create(new JsonSerializerSettings
|
|
{
|
|
ContractResolver = new DefaultContractResolver
|
|
{
|
|
NamingStrategy = new SnakeCaseNamingStrategy()
|
|
}
|
|
});
|
|
|
|
using var stream = new JsonTextReader(jsonFile.OpenText());
|
|
|
|
var obj = serializer.Deserialize<T>(stream);
|
|
if (obj is null)
|
|
{
|
|
throw new InvalidDataException($"Unable to deserialize {jsonFile}");
|
|
}
|
|
|
|
return obj;
|
|
}
|
|
}
|