using System.Text.Json; using SzCore.DataObjects; namespace SzCore; public class SzParser { private readonly JsonSerializerOptions _jsonOptions = new() { WriteIndented = true }; public string SerializeDatasetToJson(SzDataset dataset) { try { var jsonString = JsonSerializer.Serialize(dataset, _jsonOptions); return jsonString; } catch (JsonException e) { throw new Exception("Parse Error: " + e.Message); } } public SzDataset? DeserializeDataset(string jsonString) { try { var result = JsonSerializer.Deserialize(jsonString, _jsonOptions); return result; } catch (Exception e) { SZ.Logger.LogError("Could not deserialize JSON to type SzDataset: " + e.Message); return null; } } }