summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-08-14 07:55:21 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-08-14 07:55:21 -0400
commit67b1a8398f665a745f57f6d53532e504979ea40f (patch)
tree8633cb5f814c96056b93e0edf3a3560ebd10cc90 /src
parent56c66ca4e550ae482ad82dd7f87b0b1fa6adfb60 (diff)
downloadSMAPI-67b1a8398f665a745f57f6d53532e504979ea40f.tar.gz
SMAPI-67b1a8398f665a745f57f6d53532e504979ea40f.tar.bz2
SMAPI-67b1a8398f665a745f57f6d53532e504979ea40f.zip
fix SemanticVersion not being deserialisable through Json.NET
Diffstat (limited to 'src')
-rw-r--r--src/StardewModdingAPI.Tests/Utilities/SemanticVersionTests.cs17
-rw-r--r--src/StardewModdingAPI/SemanticVersion.cs16
2 files changed, 26 insertions, 7 deletions
diff --git a/src/StardewModdingAPI.Tests/Utilities/SemanticVersionTests.cs b/src/StardewModdingAPI.Tests/Utilities/SemanticVersionTests.cs
index db46aee4..03cd26c9 100644
--- a/src/StardewModdingAPI.Tests/Utilities/SemanticVersionTests.cs
+++ b/src/StardewModdingAPI.Tests/Utilities/SemanticVersionTests.cs
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics.CodeAnalysis;
+using Newtonsoft.Json;
using NUnit.Framework;
using StardewModdingAPI.Framework;
@@ -208,6 +209,22 @@ namespace StardewModdingAPI.Tests.Utilities
}
/****
+ ** Serialisable
+ ****/
+ [Test(Description = "Assert that SemanticVersion can be round-tripped through JSON with no special configuration.")]
+ [TestCase("1.0")]
+ public void Serialisable(string versionStr)
+ {
+ // act
+ string json = JsonConvert.SerializeObject(new SemanticVersion(versionStr));
+ SemanticVersion after = JsonConvert.DeserializeObject<SemanticVersion>(json);
+
+ // assert
+ Assert.IsNotNull(after, "The semantic version after deserialisation is unexpectedly null.");
+ Assert.AreEqual(versionStr, after.ToString(), "The semantic version after deserialisation doesn't match the input version.");
+ }
+
+ /****
** GameVersion
****/
[Test(Description = "Assert that the GameVersion subclass correctly parses legacy game versions.")]
diff --git a/src/StardewModdingAPI/SemanticVersion.cs b/src/StardewModdingAPI/SemanticVersion.cs
index 26de3aa8..e448eae1 100644
--- a/src/StardewModdingAPI/SemanticVersion.cs
+++ b/src/StardewModdingAPI/SemanticVersion.cs
@@ -1,5 +1,6 @@
using System;
using System.Text.RegularExpressions;
+using Newtonsoft.Json;
namespace StardewModdingAPI
{
@@ -40,15 +41,16 @@ namespace StardewModdingAPI
** Public methods
*********/
/// <summary>Construct an instance.</summary>
- /// <param name="major">The major version incremented for major API changes.</param>
- /// <param name="minor">The minor version incremented for backwards-compatible changes.</param>
- /// <param name="patch">The patch version for backwards-compatible bug fixes.</param>
+ /// <param name="majorVersion">The major version incremented for major API changes.</param>
+ /// <param name="minorVersion">The minor version incremented for backwards-compatible changes.</param>
+ /// <param name="patchVersion">The patch version for backwards-compatible bug fixes.</param>
/// <param name="build">An optional build tag.</param>
- public SemanticVersion(int major, int minor, int patch, string build = null)
+ [JsonConstructor]
+ public SemanticVersion(int majorVersion, int minorVersion, int patchVersion, string build = null)
{
- this.MajorVersion = major;
- this.MinorVersion = minor;
- this.PatchVersion = patch;
+ this.MajorVersion = majorVersion;
+ this.MinorVersion = minorVersion;
+ this.PatchVersion = patchVersion;
this.Build = this.GetNormalisedTag(build);
}