Templates
This commit is contained in:
@@ -17,7 +17,7 @@ public class SzParser
|
||||
}
|
||||
catch (JsonException e)
|
||||
{
|
||||
throw new Exception("Parse Error: " + e.Message);
|
||||
throw new Exception("Dataset Serialization Error: " + e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,5 +34,33 @@ public class SzParser
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public string SerializeTemplateToJson(ISzTemplate template)
|
||||
{
|
||||
try
|
||||
{
|
||||
var templateType = template.GetType();
|
||||
var jsonString = JsonSerializer.Serialize(template, templateType, _jsonOptions);
|
||||
return jsonString;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception("Template Serialization Error: " + e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public T? DeserializeTemplate<T>(string jsonString)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = JsonSerializer.Deserialize<T>(jsonString, _jsonOptions);
|
||||
return result;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
SZ.Logger.LogError($"Could not deserialize JSON to type {typeof(T)}: " + e.Message);
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user