diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-05-06 18:06:47 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-05-06 18:06:47 -0400 |
commit | b834ed7ef5095203529f8b77aee3f25f5387fbcc (patch) | |
tree | eca5df4cc0f4d4e7aa18ef949aeb0a9cd9ec9617 /src/SMAPI.Toolkit | |
parent | 87d5288287520f750651667839ebbe7bbeb97bba (diff) | |
download | SMAPI-b834ed7ef5095203529f8b77aee3f25f5387fbcc.tar.gz SMAPI-b834ed7ef5095203529f8b77aee3f25f5387fbcc.tar.bz2 SMAPI-b834ed7ef5095203529f8b77aee3f25f5387fbcc.zip |
fix errors reading empty JSON files
Diffstat (limited to 'src/SMAPI.Toolkit')
-rw-r--r-- | src/SMAPI.Toolkit/Serialization/JsonHelper.cs | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/src/SMAPI.Toolkit/Serialization/JsonHelper.cs b/src/SMAPI.Toolkit/Serialization/JsonHelper.cs index 3c9308f2..1a003c51 100644 --- a/src/SMAPI.Toolkit/Serialization/JsonHelper.cs +++ b/src/SMAPI.Toolkit/Serialization/JsonHelper.cs @@ -108,12 +108,11 @@ namespace StardewModdingAPI.Toolkit.Serialization /// <summary>Deserialize JSON text if possible.</summary> /// <typeparam name="TModel">The model type.</typeparam> /// <param name="json">The raw JSON text.</param> - public TModel Deserialize<TModel>(string json) + public TModel? Deserialize<TModel>(string json) { try { - return JsonConvert.DeserializeObject<TModel>(json, this.JsonSettings) - ?? throw new InvalidOperationException($"Couldn't deserialize model type '{typeof(TModel)}' from empty or null JSON."); + return JsonConvert.DeserializeObject<TModel>(json, this.JsonSettings); } catch (JsonReaderException) { |