diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-09-18 13:08:38 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-09-18 13:08:38 -0400 |
commit | ebe41180c41f544919c03fb3bf6029437a7d65a4 (patch) | |
tree | 0c5c0602bbee1fc96a024f3be1cd225d72d37fa0 /src/SMAPI.Toolkit | |
parent | c5b8cd626489dad6210fe629658314dfc85f4d08 (diff) | |
parent | 6643da4574bec2d71ac9c25a2c9ab15b8c855e2b (diff) | |
download | SMAPI-ebe41180c41f544919c03fb3bf6029437a7d65a4.tar.gz SMAPI-ebe41180c41f544919c03fb3bf6029437a7d65a4.tar.bz2 SMAPI-ebe41180c41f544919c03fb3bf6029437a7d65a4.zip |
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI.Toolkit')
-rw-r--r-- | src/SMAPI.Toolkit/Serialization/Converters/SimpleReadOnlyConverter.cs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/SMAPI.Toolkit/Serialization/Converters/SimpleReadOnlyConverter.cs b/src/SMAPI.Toolkit/Serialization/Converters/SimpleReadOnlyConverter.cs index 549f0c18..ccc5158b 100644 --- a/src/SMAPI.Toolkit/Serialization/Converters/SimpleReadOnlyConverter.cs +++ b/src/SMAPI.Toolkit/Serialization/Converters/SimpleReadOnlyConverter.cs @@ -22,7 +22,7 @@ namespace StardewModdingAPI.Toolkit.Serialization.Converters /// <param name="objectType">The object type.</param> public override bool CanConvert(Type objectType) { - return objectType == typeof(T); + return objectType == typeof(T) || Nullable.GetUnderlyingType(objectType) == typeof(T); } /// <summary>Writes the JSON representation of the object.</summary> @@ -44,10 +44,15 @@ namespace StardewModdingAPI.Toolkit.Serialization.Converters string path = reader.Path; switch (reader.TokenType) { + case JsonToken.Null when Nullable.GetUnderlyingType(objectType) != null: + return null; + case JsonToken.StartObject: return this.ReadObject(JObject.Load(reader), path); + case JsonToken.String: return this.ReadString(JToken.Load(reader).Value<string>(), path); + default: throw new SParseException($"Can't parse {typeof(T).Name} from {reader.TokenType} node (path: {reader.Path})."); } |