summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/SMAPI.Toolkit/Serialization/JsonHelper.cs6
-rw-r--r--src/SMAPI/Events/ModMessageReceivedEventArgs.cs10
-rw-r--r--src/SMAPI/Framework/SCore.cs2
3 files changed, 15 insertions, 3 deletions
diff --git a/src/SMAPI.Toolkit/Serialization/JsonHelper.cs b/src/SMAPI.Toolkit/Serialization/JsonHelper.cs
index 031afbb0..00db9903 100644
--- a/src/SMAPI.Toolkit/Serialization/JsonHelper.cs
+++ b/src/SMAPI.Toolkit/Serialization/JsonHelper.cs
@@ -132,5 +132,11 @@ namespace StardewModdingAPI.Toolkit.Serialization
{
return JsonConvert.SerializeObject(model, formatting, this.JsonSettings);
}
+
+ /// <summary>Get a low-level JSON serializer matching the <see cref="JsonSettings"/>.</summary>
+ public JsonSerializer GetSerializer()
+ {
+ return JsonSerializer.CreateDefault(this.JsonSettings);
+ }
}
}
diff --git a/src/SMAPI/Events/ModMessageReceivedEventArgs.cs b/src/SMAPI/Events/ModMessageReceivedEventArgs.cs
index d4370028..d75a7540 100644
--- a/src/SMAPI/Events/ModMessageReceivedEventArgs.cs
+++ b/src/SMAPI/Events/ModMessageReceivedEventArgs.cs
@@ -1,5 +1,6 @@
using System;
using StardewModdingAPI.Framework.Networking;
+using StardewModdingAPI.Toolkit.Serialization;
namespace StardewModdingAPI.Events
{
@@ -12,6 +13,9 @@ namespace StardewModdingAPI.Events
/// <summary>The underlying message model.</summary>
private readonly ModMessageModel Message;
+ /// <summary>The JSON helper used to deserialize models.</summary>
+ private readonly JsonHelper JsonHelper;
+
/*********
** Accessors
@@ -31,16 +35,18 @@ namespace StardewModdingAPI.Events
*********/
/// <summary>Construct an instance.</summary>
/// <param name="message">The received message.</param>
- internal ModMessageReceivedEventArgs(ModMessageModel message)
+ /// <param name="jsonHelper">The JSON helper used to deserialize models.</param>
+ internal ModMessageReceivedEventArgs(ModMessageModel message, JsonHelper jsonHelper)
{
this.Message = message;
+ this.JsonHelper = jsonHelper;
}
/// <summary>Read the message data into the given model type.</summary>
/// <typeparam name="TModel">The message model type.</typeparam>
public TModel ReadAs<TModel>()
{
- return this.Message.Data.ToObject<TModel>();
+ return this.Message.Data.ToObject<TModel>(this.JsonHelper.GetSerializer());
}
}
}
diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs
index 27540442..5dc33828 100644
--- a/src/SMAPI/Framework/SCore.cs
+++ b/src/SMAPI/Framework/SCore.cs
@@ -1128,7 +1128,7 @@ namespace StardewModdingAPI.Framework
modIDs.Remove(message.FromModID); // don't send a broadcast back to the sender
// raise events
- this.EventManager.ModMessageReceived.Raise(new ModMessageReceivedEventArgs(message), mod => mod != null && modIDs.Contains(mod.Manifest.UniqueID));
+ this.EventManager.ModMessageReceived.Raise(new ModMessageReceivedEventArgs(message, this.Toolkit.JsonHelper), mod => mod != null && modIDs.Contains(mod.Manifest.UniqueID));
}
/// <summary>Constructor a content manager to read game content files.</summary>