diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2018-11-19 13:48:19 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2018-11-19 13:48:19 -0500 |
commit | 593723b7940ba72a786fc4c7366c56f9813d977b (patch) | |
tree | 4d23fbef5bc5a20115f10ca04ae3379df78cc8e1 /src/StardewModdingAPI.Toolkit/Serialisation/JsonHelper.cs | |
parent | 4f28ea33bd7cc65485402c5e85259083e86b49e1 (diff) | |
parent | 3dc27a5681dcfc4ae30e95570d9966f2e14a4dd7 (diff) | |
download | SMAPI-593723b7940ba72a786fc4c7366c56f9813d977b.tar.gz SMAPI-593723b7940ba72a786fc4c7366c56f9813d977b.tar.bz2 SMAPI-593723b7940ba72a786fc4c7366c56f9813d977b.zip |
Merge branch 'develop' into stable
Diffstat (limited to 'src/StardewModdingAPI.Toolkit/Serialisation/JsonHelper.cs')
-rw-r--r-- | src/StardewModdingAPI.Toolkit/Serialisation/JsonHelper.cs | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/StardewModdingAPI.Toolkit/Serialisation/JsonHelper.cs b/src/StardewModdingAPI.Toolkit/Serialisation/JsonHelper.cs index cc8eeb73..cf2ce0d1 100644 --- a/src/StardewModdingAPI.Toolkit/Serialisation/JsonHelper.cs +++ b/src/StardewModdingAPI.Toolkit/Serialisation/JsonHelper.cs @@ -95,18 +95,14 @@ namespace StardewModdingAPI.Toolkit.Serialisation Directory.CreateDirectory(dir); // write file - string json = JsonConvert.SerializeObject(model, this.JsonSettings); + string json = this.Serialise(model); File.WriteAllText(fullPath, json); } - - /********* - ** Private methods - *********/ /// <summary>Deserialize JSON text if possible.</summary> /// <typeparam name="TModel">The model type.</typeparam> /// <param name="json">The raw JSON text.</param> - private TModel Deserialise<TModel>(string json) + public TModel Deserialise<TModel>(string json) { try { @@ -127,5 +123,14 @@ namespace StardewModdingAPI.Toolkit.Serialisation throw; } } + + /// <summary>Serialize a model to JSON text.</summary> + /// <typeparam name="TModel">The model type.</typeparam> + /// <param name="model">The model to serialise.</param> + /// <param name="formatting">The formatting to apply.</param> + public string Serialise<TModel>(TModel model, Formatting formatting = Formatting.Indented) + { + return JsonConvert.SerializeObject(model, formatting, this.JsonSettings); + } } } |