mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-04-13 20:47:24 +00:00
feat: Adding shorthand method for serializing an object into a JSON message
This commit is contained in:
parent
a9a544c433
commit
d564a0a423
1 changed files with 16 additions and 0 deletions
|
|
@ -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.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue