Added data evaluation, made parser more robust, switched to NewtonSoft json
This commit is contained in:
@@ -1,19 +1,22 @@
|
||||
using System.Text.Json;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using SzCore.DataObjects;
|
||||
|
||||
namespace SzCore;
|
||||
|
||||
public class SzParser
|
||||
{
|
||||
|
||||
private readonly JsonSerializerOptions _jsonOptions = new() { WriteIndented = true };
|
||||
private readonly JsonSerializerSettings _jsonSettings = new()
|
||||
{
|
||||
Formatting = Formatting.Indented,
|
||||
Converters = { new StringEnumConverter() }
|
||||
};
|
||||
|
||||
public string SerializeDatasetToJson(SzDataset dataset)
|
||||
{
|
||||
try
|
||||
{
|
||||
var jsonString = JsonSerializer.Serialize(dataset, _jsonOptions);
|
||||
return jsonString;
|
||||
return JsonConvert.SerializeObject(dataset, _jsonSettings);
|
||||
}
|
||||
catch (JsonException e)
|
||||
{
|
||||
@@ -25,8 +28,7 @@ public class SzParser
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = JsonSerializer.Deserialize<SzDataset>(jsonString, _jsonOptions);
|
||||
return result;
|
||||
return JsonConvert.DeserializeObject<SzDataset>(jsonString, _jsonSettings);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -39,9 +41,7 @@ public class SzParser
|
||||
{
|
||||
try
|
||||
{
|
||||
var templateType = template.GetType();
|
||||
var jsonString = JsonSerializer.Serialize(template, templateType, _jsonOptions);
|
||||
return jsonString;
|
||||
return JsonConvert.SerializeObject(template, _jsonSettings);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -53,8 +53,7 @@ public class SzParser
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = JsonSerializer.Deserialize<T>(jsonString, _jsonOptions);
|
||||
return result;
|
||||
return JsonConvert.DeserializeObject<T>(jsonString, _jsonSettings);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -62,5 +61,4 @@ public class SzParser
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user