From d564a0a423d9462aeee9493260ee95c47e121140 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Thu, 24 Jan 2019 16:21:29 -0500 Subject: [PATCH] feat: Adding shorthand method for serializing an object into a JSON message --- ICD.Common.Utils/Json/JsonUtils.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ICD.Common.Utils/Json/JsonUtils.cs b/ICD.Common.Utils/Json/JsonUtils.cs index 059d631..870bc56 100644 --- a/ICD.Common.Utils/Json/JsonUtils.cs +++ b/ICD.Common.Utils/Json/JsonUtils.cs @@ -187,6 +187,22 @@ namespace ICD.Common.Utils.Json } } + /// + /// Serializes to json, wrapping the object with a message property to differentiate between messages. + /// E.g. + /// { a = 1 } + /// Becomes + /// { m = "Test", d = { a = 1 } } + /// + /// + /// + /// + [PublicAPI] + public static string SerializeMessage(object value, string messageName) + { + return SerializeMessage(w => new JsonSerializer().Serialize(w, value), messageName); + } + /// /// Serializes to json, wrapping the object with a message property to differentiate between messages. /// E.g.