Skip to content

Commit

Permalink
Catch errors for type mismatch in json files
Browse files Browse the repository at this point in the history
  • Loading branch information
chirpxiv committed Jun 16, 2023
1 parent 6429160 commit 4e019aa
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Ktisis/Data/Serialization/Converters/JsonFileConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Text.Json;
using System.Text.Json.Serialization;

using Dalamud.Logging;

using Ktisis.Data.Files;

namespace Ktisis.Data.Serialization.Converters {
Expand All @@ -21,8 +23,12 @@ public class JsonFileConverter : JsonConverter<JsonFile> {
continue;
}

var value = JsonSerializer.Deserialize(jsonValue, prop.PropertyType, options);
prop.SetValue(result, value);
try {
var value = jsonValue.Deserialize(prop.PropertyType, options);
if (value != null) prop.SetValue(result, value);
} catch {
PluginLog.Warning($"Failed to parse {prop.PropertyType.Name} value '{prop.Name}' (received {jsonValue.ValueKind} instead)");
}
}

return result;
Expand Down

0 comments on commit 4e019aa

Please sign in to comment.