Class JsonHelper
Helper class for JSON serialization, deserialization, patch creation and patch application
Inherited Members
Namespace: DuetAPI.Utility
Assembly: DuetAPI.dll
Syntax
public static class JsonHelper
Fields
DefaultJsonOptions
Default JSON (de-)serialization options
Declaration
public static readonly JsonSerializerOptions DefaultJsonOptions
Field Value
| Type | Description |
|---|---|
| JsonSerializerOptions |
Methods
ToObject(JsonElement, Type, JsonSerializerOptions?)
Convert a JsonElement to an object
Declaration
public static object? ToObject(this JsonElement element, Type type, JsonSerializerOptions? options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonElement | element | Element to deserialize |
| Type | type | Object type |
| JsonSerializerOptions | options | JSON serializer options |
Returns
| Type | Description |
|---|---|
| object | Deserialized object |
Remarks
The original code is from https://stackoverflow.com/questions/58138793/system-text-json-jsonelement-toobject-workaround and it will become obsolete when DSF is migrated to .NET Core 5.
ToObject<T>(JsonDocument, JsonSerializerOptions?)
Convert a JsonDocument to an object
Declaration
public static T? ToObject<T>(this JsonDocument document, JsonSerializerOptions? options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonDocument | document | Document to deserialize |
| JsonSerializerOptions | options | JSON serializer options |
Returns
| Type | Description |
|---|---|
| T | Deserialized object |
Type Parameters
| Name | Description |
|---|---|
| T | Object type |
Remarks
The original code is from https://stackoverflow.com/questions/58138793/system-text-json-jsonelement-toobject-workaround
ToObject<T>(JsonElement, JsonSerializerOptions?)
Convert a JsonElement to an object
Declaration
public static T? ToObject<T>(this JsonElement element, JsonSerializerOptions? options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonElement | element | Element to deserialize |
| JsonSerializerOptions | options | JSON serializer options |
Returns
| Type | Description |
|---|---|
| T | Deserialized object |
Type Parameters
| Name | Description |
|---|---|
| T | Object type |
Remarks
The original code is from https://stackoverflow.com/questions/58138793/system-text-json-jsonelement-toobject-workaround