Method SerializeJson
| Edit this page View SourceSerializeJson<T>(IGrid<T>)
Serializes any grid to a byte array using JSON encoding for the data. This is the universal fallback method that works with any grid type, including managed types and complex objects that cannot be directly serialized to binary.
Declaration
public static byte[] SerializeJson<T>(this IGrid<T> grid)
Parameters
| Type | Name | Description |
|---|---|---|
| IGrid<T> | grid | The grid instance to serialize. |
Returns
| Type | Description |
|---|---|
| byte[] | A byte array containing the complete serialized grid (metadata + data). |
Type Parameters
| Name | Description |
|---|---|
| T | The type of values stored in the grid. Can be any serializable type. |
Remarks
This method uses JSON serialization for the data portion, making it compatible with any JSON-serializable type but less efficient than binary serialization for simple value types.
For better performance with unmanaged value types, consider using SerializeBinary<T>(IGrid<T>) instead.
The resulting format includes grid metadata (dimensions, voxel size) and type information, allowing for complete reconstruction of the grid during deserialization.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
| NotSupportedException | Thrown when the grid type T is not JSON serializable. |