Class JsonSerialization
High level API for serializing or deserializing json data from string, file or stream.
Namespace: Unity.Serialization.Json
Syntax
public static class JsonSerialization : object
Methods
AddGlobalAdapter(IJsonAdapter)
Adds the specified IJsonAdapter to the set of global adapters. This is be included by default in all JsonSerialization calls.
Declaration
public static void AddGlobalAdapter(IJsonAdapter adapter)
Parameters
| Type | Name | Description |
|---|---|---|
| IJsonAdapter | adapter | The adapter to add. |
AddGlobalMigration(IJsonMigration)
Adds the specified IJsonMigration to the set of global adapters. This is be included by default in all JsonSerialization calls.
Declaration
public static void AddGlobalMigration(IJsonMigration migration)
Parameters
| Type | Name | Description |
|---|---|---|
| IJsonMigration | migration | The migration to add. |
FromJson<T>(FileInfo, JsonSerializationParameters)
Deserializes from the specified path and returns a new instance of T.
Declaration
public static T FromJson<T>(FileInfo file, JsonSerializationParameters parameters = default(JsonSerializationParameters))
Parameters
| Type | Name | Description |
|---|---|---|
| FileInfo | file | The file to read from. |
| JsonSerializationParameters | parameters | The reader parameters to use. |
Returns
| Type | Description |
|---|---|
| T | A new instance of |
Type Parameters
| Name | Description |
|---|---|
| T | The type to deserialize. |
FromJson<T>(Stream, JsonSerializationParameters)
Deserializes from the specified stream and returns a new instance of T.
Declaration
public static T FromJson<T>(Stream stream, JsonSerializationParameters parameters = default(JsonSerializationParameters))
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | The stream to read from. |
| JsonSerializationParameters | parameters | The reader parameters to use. |
Returns
| Type | Description |
|---|---|
| T | A new instance of |
Type Parameters
| Name | Description |
|---|---|
| T | The type to deserialize. |
FromJson<T>(String, JsonSerializationParameters)
Deserializes from the specified json string and returns a new instance of T.
Declaration
public static T FromJson<T>(string json, JsonSerializationParameters parameters = default(JsonSerializationParameters))
Parameters
| Type | Name | Description |
|---|---|---|
| String | json | The json string to read from. |
| JsonSerializationParameters | parameters | The reader parameters to use. |
Returns
| Type | Description |
|---|---|
| T | A new instance of |
Type Parameters
| Name | Description |
|---|---|
| T | The type to deserialize. |
FromJsonOverride<T>(FileInfo, ref T, JsonSerializationParameters)
Deserializes from the specified path in to an existing instance of T.
Declaration
public static void FromJsonOverride<T>(FileInfo file, ref T container, JsonSerializationParameters parameters = default(JsonSerializationParameters))
Parameters
| Type | Name | Description |
|---|---|---|
| FileInfo | file | The file to read from. |
| T | container | The reference to be overwritten. |
| JsonSerializationParameters | parameters | The reader parameters to use. |
Type Parameters
| Name | Description |
|---|---|
| T | The type to deserialize. |
FromJsonOverride<T>(Stream, ref T, JsonSerializationParameters)
Deserializes from the specified stream in to an existing instance of T.
Declaration
public static void FromJsonOverride<T>(Stream stream, ref T container, JsonSerializationParameters parameters = default(JsonSerializationParameters))
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | The stream to read from. |
| T | container | The reference to be overwritten. |
| JsonSerializationParameters | parameters | The reader parameters to use. |
Type Parameters
| Name | Description |
|---|---|
| T | The type to deserialize. |
FromJsonOverride<T>(String, ref T, JsonSerializationParameters)
Deserializes from the specified json string in to an existing instance of T.
Declaration
public static void FromJsonOverride<T>(string json, ref T container, JsonSerializationParameters parameters = default(JsonSerializationParameters))
Parameters
| Type | Name | Description |
|---|---|---|
| String | json | The json string to read from. |
| T | container | The reference to be overwritten. |
| JsonSerializationParameters | parameters | The reader parameters to use. |
Type Parameters
| Name | Description |
|---|---|
| T | The type to deserialize. |
RemoveGlobalAdapter(IJsonAdapter)
Removes the specified IJsonAdapter from the set of global adapters.
Declaration
public static void RemoveGlobalAdapter(IJsonAdapter adapter)
Parameters
| Type | Name | Description |
|---|---|---|
| IJsonAdapter | adapter | The adapter to remove. |
RemoveGlobalMigration(IJsonMigration)
Removes the specified IJsonAdapter from the set of global adapters.
Declaration
public static void RemoveGlobalMigration(IJsonMigration migration)
Parameters
| Type | Name | Description |
|---|---|---|
| IJsonMigration | migration | The migration to remove. |
ToJson<T>(T, JsonSerializationParameters)
Writes a property container to a json string.
Declaration
public static string ToJson<T>(T value, JsonSerializationParameters parameters = default(JsonSerializationParameters))
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | The container to write. |
| JsonSerializationParameters | parameters | The parameters to use when writing. |
Returns
| Type | Description |
|---|---|
| String | A json string. |
Type Parameters
| Name | Description |
|---|---|
| T | The type to serialize. |
ToJson<T>(FileInfo, T, JsonSerializationParameters)
Serializes the given object to a json file at the specified path.
Declaration
public static void ToJson<T>(FileInfo file, T container, JsonSerializationParameters parameters = default(JsonSerializationParameters))
Parameters
| Type | Name | Description |
|---|---|---|
| FileInfo | file | The file to write to. |
| T | container | The object to serialize. |
| JsonSerializationParameters | parameters | The parameters to use when writing. |
Type Parameters
| Name | Description |
|---|---|
| T | The type to serialize. |
ToJson<T>(JsonStringBuffer, T, JsonSerializationParameters)
Writes a property container the specified buffer.
Declaration
public static void ToJson<T>(JsonStringBuffer buffer, T value, JsonSerializationParameters parameters = default(JsonSerializationParameters))
Parameters
| Type | Name | Description |
|---|---|---|
| JsonStringBuffer | buffer | The buffer to write the object to. |
| T | value | The container to write. |
| JsonSerializationParameters | parameters | The parameters to use when writing. |
Type Parameters
| Name | Description |
|---|---|
| T | The type to serialize. |
ToJson<T>(JsonWriter, T, JsonSerializationParameters)
Writes a property container the specified buffer.
Declaration
public static void ToJson<T>(JsonWriter writer, T value, JsonSerializationParameters parameters = default(JsonSerializationParameters))
Parameters
| Type | Name | Description |
|---|---|---|
| JsonWriter | writer | The buffer to write the object to. |
| T | value | The container to write. |
| JsonSerializationParameters | parameters | The parameters to use when writing. |
Type Parameters
| Name | Description |
|---|---|
| T | The type to serialize. |
TryFromJson<T>(FileInfo, out T, out DeserializationResult, JsonSerializationParameters)
Deserializes from the specified path and returns a new instance of T.
Declaration
public static bool TryFromJson<T>(FileInfo file, out T container, out DeserializationResult result, JsonSerializationParameters parameters = default(JsonSerializationParameters))
Parameters
| Type | Name | Description |
|---|---|---|
| FileInfo | file | The file to read from. |
| T | container | When this method returns, contains the deserialized value. |
| DeserializationResult | result | The results structure containing any errors or exceptions. |
| JsonSerializationParameters | parameters | The reader parameters to use. |
Returns
| Type | Description |
|---|---|
| Boolean | True if the deserialization succeeded; otherwise, false. |
Type Parameters
| Name | Description |
|---|---|
| T | The type to deserialize. |
TryFromJson<T>(Stream, out T, out DeserializationResult, JsonSerializationParameters)
Deserializes from the specified stream and returns a new instance of T.
Declaration
public static bool TryFromJson<T>(Stream stream, out T container, out DeserializationResult result, JsonSerializationParameters parameters = default(JsonSerializationParameters))
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | The stream to read from. |
| T | container | When this method returns, contains the deserialized value. |
| DeserializationResult | result | The results structure containing any errors or exceptions. |
| JsonSerializationParameters | parameters | The reader parameters to use. |
Returns
| Type | Description |
|---|---|
| Boolean | True if the deserialization succeeded; otherwise, false. |
Type Parameters
| Name | Description |
|---|---|
| T | The type to deserialize. |
TryFromJson<T>(String, out T, out DeserializationResult, JsonSerializationParameters)
Deserializes from the specified json string and returns a new instance of T.
Declaration
public static bool TryFromJson<T>(string json, out T container, out DeserializationResult result, JsonSerializationParameters parameters = default(JsonSerializationParameters))
Parameters
| Type | Name | Description |
|---|---|---|
| String | json | The json string to read from. |
| T | container | When this method returns, contains the deserialized value. |
| DeserializationResult | result | The results structure containing any errors or exceptions. |
| JsonSerializationParameters | parameters | The reader parameters to use. |
Returns
| Type | Description |
|---|---|
| Boolean | True if the deserialization succeeded; otherwise, false. |
Type Parameters
| Name | Description |
|---|---|
| T | The type to deserialize. |
TryFromJsonOverride<T>(FileInfo, ref T, out DeserializationResult, JsonSerializationParameters)
Deserializes from the specified path in to an existing instance of T.
Declaration
public static bool TryFromJsonOverride<T>(FileInfo file, ref T container, out DeserializationResult result, JsonSerializationParameters parameters = default(JsonSerializationParameters))
Parameters
| Type | Name | Description |
|---|---|---|
| FileInfo | file | The file to read from. |
| T | container | The reference to be overwritten. |
| DeserializationResult | result | The results structure containing any errors or exceptions. |
| JsonSerializationParameters | parameters | The reader parameters to use. |
Returns
| Type | Description |
|---|---|
| Boolean | True if the deserialization succeeded; otherwise, false. |
Type Parameters
| Name | Description |
|---|---|
| T | The type to deserialize. |
TryFromJsonOverride<T>(Stream, ref T, out DeserializationResult, JsonSerializationParameters)
Deserializes from the specified stream in to an existing instance of T.
Declaration
public static bool TryFromJsonOverride<T>(Stream stream, ref T container, out DeserializationResult result, JsonSerializationParameters parameters = default(JsonSerializationParameters))
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | The stream to read from. |
| T | container | The reference to be overwritten. |
| DeserializationResult | result | The results structure containing any errors or exceptions. |
| JsonSerializationParameters | parameters | The reader parameters to use. |
Returns
| Type | Description |
|---|---|
| Boolean | True if the deserialization succeeded; otherwise, false. |
Type Parameters
| Name | Description |
|---|---|
| T | The type to deserialize. |
TryFromJsonOverride<T>(String, ref T, out DeserializationResult, JsonSerializationParameters)
Deserializes from the specified json string in to an existing instance of T.
Declaration
public static bool TryFromJsonOverride<T>(string json, ref T container, out DeserializationResult result, JsonSerializationParameters parameters = default(JsonSerializationParameters))
Parameters
| Type | Name | Description |
|---|---|---|
| String | json | The json string to read from. |
| T | container | The reference to be overwritten. |
| DeserializationResult | result | The results structure containing any errors or exceptions. |
| JsonSerializationParameters | parameters | The reader parameters to use. |
Returns
| Type | Description |
|---|---|
| Boolean | True if the deserialization succeeded; otherwise, false. |
Type Parameters
| Name | Description |
|---|---|
| T | The type to deserialize. |