mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 13:15:07 +00:00
feat: Adding shorthand method for serializing an object into a JSON message
This commit is contained in:
@@ -187,6 +187,22 @@ namespace ICD.Common.Utils.Json
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Serializes to json, wrapping the object with a message property to differentiate between messages.
|
||||||
|
/// E.g.
|
||||||
|
/// { a = 1 }
|
||||||
|
/// Becomes
|
||||||
|
/// { m = "Test", d = { a = 1 } }
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <param name="messageName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[PublicAPI]
|
||||||
|
public static string SerializeMessage(object value, string messageName)
|
||||||
|
{
|
||||||
|
return SerializeMessage(w => new JsonSerializer().Serialize(w, value), messageName);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Serializes to json, wrapping the object with a message property to differentiate between messages.
|
/// Serializes to json, wrapping the object with a message property to differentiate between messages.
|
||||||
/// E.g.
|
/// E.g.
|
||||||
|
|||||||
Reference in New Issue
Block a user