PluginJson
Static class in Oadm.Sdk.Plugins · Oadm.Sdk.dll
The JSON of a plugin’s page calls, events, task payloads and stored settings, shared by its server and client part: the common serializer options and parse methods with one error rule. An empty or broken text from a caller is an ArgumentException with a plain message, which the server answers as a refusal (INVALID_ARGUMENT), never as a failure of the plugin. The message never quotes the text or the reader’s own error: a payload may hold a password. SDK 0.12.0.
public static class PluginJsonGuide: Core plugins and pages
A plugin keeps the options in a static of its own (PluginJson.CreateOptions): the serializer remembers the plugin’s types in them, and they must go away with the plugin when it is unloaded.
Methods
Section titled “Methods”CreateOptions
Section titled “CreateOptions”static JsonSerializerOptions CreateOptions(PluginJsonEnums enums = Numbers, bool writeNulls = false)New options with the common settings: camelCase names, names read in any case, numbers also read from strings (JsonSerializerDefaults.Web), and null values left out unless writeNulls. Create them once per plugin and keep them in a static field.
static T Parse<T>(string? json, JsonSerializerOptions options)The value of a text that must be there. No text, blank text or null: ArgumentException (PluginJson.EmptyRequest); broken JSON: ArgumentException (PluginJson.UnreadableRequest).
ParseOrEmpty
Section titled “ParseOrEmpty”static T ParseOrEmpty<T>(string? json, JsonSerializerOptions options)The value of a text that may be left out: no text, blank text or null reads like {}, every member at its default. Broken JSON: ArgumentException (PluginJson.UnreadableRequest).
Serialize
Section titled “Serialize”static string Serialize<T>(T value, JsonSerializerOptions options)The JSON text of value.
TryParse
Section titled “TryParse”static T? TryParse<T>(string? json, JsonSerializerOptions options) where T : classThe value of stored text that may be missing or damaged (settings, records, files): null for no text, blank text, null or broken JSON. Never throws for the text.
Fields
Section titled “Fields”EmptyRequest
Section titled “EmptyRequest”const string EmptyRequest = "The request is empty."What PluginJson.Parse says for no text at all.
UnreadableRequest
Section titled “UnreadableRequest”const string UnreadableRequest = "The request cannot be read."What the parse methods say for text that is not the expected JSON.