Class JsonSerialization
High level API for serializing or deserializing json data from string, file or stream.
Inherited Members
Namespace: Unity.Serialization.Json
Assembly: Unity.Serialization.dll
Syntax
public static class JsonSerialization
Methods
AddGlobalAdapter(IJsonAdapter)
Adds the specified IJson
Declaration
public static void AddGlobalAdapter(IJsonAdapter adapter)
Parameters
Type | Name | Description |
---|---|---|
IJson |
adapter | The adapter to add. |
Exceptions
Type | Condition |
---|---|
Argument |
The given adapter is already registered. |
AddGlobalMigration(IJsonMigration)
Adds the specified IJson
Declaration
public static void AddGlobalMigration(IJsonMigration migration)
Parameters
Type | Name | Description |
---|---|---|
IJson |
migration | The migration to add. |
Exceptions
Type | Condition |
---|---|
Argument |
The given migration is already registered. |
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)
Parameters
Type | Name | Description |
---|---|---|
File |
file | The file to read from. |
T | container | The reference to be overwritten. |
Json |
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)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | The stream to read from. |
T | container | The reference to be overwritten. |
Json |
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)
Parameters
Type | Name | Description |
---|---|---|
string | json | The json string to read from. |
T | container | The reference to be overwritten. |
Json |
parameters | The reader parameters to use. |
Type Parameters
Name | Description |
---|---|
T | The type to deserialize. |
FromJsonOverride<T>(SerializedValueView, ref T, JsonSerializationParameters)
Deserializes from the specified SerializedT
.
Declaration
public static void FromJsonOverride<T>(SerializedValueView view, ref T container, JsonSerializationParameters parameters = default)
Parameters
Type | Name | Description |
---|---|---|
Serialized |
view | The view to read from. |
T | container | The reference to be overwritten. |
Json |
parameters | The reader parameters to use. |
Type Parameters
Name | Description |
---|---|
T | The type to deserialize. |
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)
Parameters
Type | Name | Description |
---|---|---|
File |
file | The file to read from. |
Json |
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)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | The stream to read from. |
Json |
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)
Parameters
Type | Name | Description |
---|---|---|
string | json | The json string to read from. |
Json |
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>(SerializedValueView, JsonSerializationParameters)
Deserializes from the specified SerializedValueView and returns a new instance of T
.
Declaration
public static T FromJson<T>(SerializedValueView view, JsonSerializationParameters parameters = default)
Parameters
Type | Name | Description |
---|---|---|
Serialized |
view | The view to read from. |
Json |
parameters | The reader parameters to use. |
Returns
Type | Description |
---|---|
T | A new instance of |
Type Parameters
Name | Description |
---|---|
T | The type to deserialize. |
RemoveGlobalAdapter(IJsonAdapter)
Removes the specified IJson
Declaration
public static void RemoveGlobalAdapter(IJsonAdapter adapter)
Parameters
Type | Name | Description |
---|---|---|
IJson |
adapter | The adapter to remove. |
Exceptions
Type | Condition |
---|---|
Argument |
The given adapter has not been registered. |
RemoveGlobalMigration(IJsonMigration)
Removes the specified IJson
Declaration
public static void RemoveGlobalMigration(IJsonMigration migration)
Parameters
Type | Name | Description |
---|---|---|
IJson |
migration | The migration to remove. |
Exceptions
Type | Condition |
---|---|
Argument |
The given migration has not been registered. |
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)
Parameters
Type | Name | Description |
---|---|---|
File |
file | The file to write to. |
T | container | The object to serialize. |
Json |
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)
Parameters
Type | Name | Description |
---|---|---|
Json |
writer | The buffer to write the object to. |
T | value | The container to write. |
Json |
parameters | The parameters to use when writing. |
Type Parameters
Name | Description |
---|---|
T | The type to serialize. |
ToJson<T>(T, JsonSerializationParameters)
Writes a property container to a json string.
Declaration
public static string ToJson<T>(T value, JsonSerializationParameters parameters = default)
Parameters
Type | Name | Description |
---|---|---|
T | value | The container to write. |
Json |
parameters | The parameters to use when writing. |
Returns
Type | Description |
---|---|
string | A json string. |
Type Parameters
Name | Description |
---|---|
T | The type to serialize. |
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)
Parameters
Type | Name | Description |
---|---|---|
File |
file | The file to read from. |
T | container | The reference to be overwritten. |
Deserialization |
result | The results structure containing any errors or exceptions. |
Json |
parameters | The reader parameters to use. |
Returns
Type | Description |
---|---|
bool | 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)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | The stream to read from. |
T | container | The reference to be overwritten. |
Deserialization |
result | The results structure containing any errors or exceptions. |
Json |
parameters | The reader parameters to use. |
Returns
Type | Description |
---|---|
bool | 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)
Parameters
Type | Name | Description |
---|---|---|
string | json | The json string to read from. |
T | container | The reference to be overwritten. |
Deserialization |
result | The results structure containing any errors or exceptions. |
Json |
parameters | The reader parameters to use. |
Returns
Type | Description |
---|---|
bool | True if the deserialization succeeded; otherwise, false. |
Type Parameters
Name | Description |
---|---|
T | The type to deserialize. |
TryFromJsonOverride<T>(SerializedValueView, ref T, out DeserializationResult, JsonSerializationParameters)
Deserializes from the specified SerializedValueView in to an existing instance of T
.
Declaration
public static bool TryFromJsonOverride<T>(SerializedValueView view, ref T container, out DeserializationResult result, JsonSerializationParameters parameters = default)
Parameters
Type | Name | Description |
---|---|---|
Serialized |
view | The view to read from. |
T | container | The reference to be overwritten. |
Deserialization |
result | The results structure containing any errors or exceptions. |
Json |
parameters | The reader parameters to use. |
Returns
Type | Description |
---|---|
bool | True if the deserialization succeeded; otherwise, false. |
Type Parameters
Name | Description |
---|---|
T | The type to deserialize. |
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)
Parameters
Type | Name | Description |
---|---|---|
File |
file | The file to read from. |
T | container | When this method returns, contains the deserialized value. |
Deserialization |
result | The results structure containing any errors or exceptions. |
Json |
parameters | The reader parameters to use. |
Returns
Type | Description |
---|---|
bool | 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)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | The stream to read from. |
T | container | When this method returns, contains the deserialized value. |
Deserialization |
result | The results structure containing any errors or exceptions. |
Json |
parameters | The reader parameters to use. |
Returns
Type | Description |
---|---|
bool | 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)
Parameters
Type | Name | Description |
---|---|---|
string | json | The json string to read from. |
T | container | When this method returns, contains the deserialized value. |
Deserialization |
result | The results structure containing any errors or exceptions. |
Json |
parameters | The reader parameters to use. |
Returns
Type | Description |
---|---|
bool | True if the deserialization succeeded; otherwise, false. |
Type Parameters
Name | Description |
---|---|
T | The type to deserialize. |
TryFromJson<T>(SerializedValueView, ref T, out DeserializationResult, JsonSerializationParameters)
Deserializes from the specified SerializedT
.
Declaration
public static bool TryFromJson<T>(SerializedValueView view, ref T container, out DeserializationResult result, JsonSerializationParameters parameters = default)
Parameters
Type | Name | Description |
---|---|---|
Serialized |
view | The view to read from. |
T | container | When this method returns, contains the deserialized value. |
Deserialization |
result | The results structure containing any errors or exceptions. |
Json |
parameters | The reader parameters to use. |
Returns
Type | Description |
---|---|
bool | True if the deserialization succeeded; otherwise, false. |
Type Parameters
Name | Description |
---|---|
T | The type to deserialize. |