Class JsonSerialization | Serialization | 0.6.4-preview
docs.unity3d.com
    Show / Hide Table of Contents

    Class JsonSerialization

    Helper class that generically writes any property container as a JSON string.

    @NOTE This class makes heavy use of StringBuilder and .ToString on primitives, which allocates large amounts of memory. Use it sparingly.

    @TODO

    • Optimization
    Inheritance
    Object
    JsonSerialization
    Namespace: Unity.Serialization.Json
    Syntax
    public static class JsonSerialization
    Remarks

    The deserialization methods will not construct type instances. All object fields must be initialized in the default constructor.

    Methods

    DeserializeFromPath<TContainer>(String)

    Deserializes the given file path and returns a new instance of the container.

    Declaration
    public static TContainer DeserializeFromPath<TContainer>(string path)
        where TContainer : new()
    Parameters
    Type Name Description
    String path

    The file path to read from.

    Returns
    Type Description
    TContainer

    A new instance of the container with based on the serialized data.

    Type Parameters
    Name Description
    TContainer

    The type to deserialize.

    DeserializeFromPath<TContainer>(String, ref TContainer)

    Deserializes the given file path and writes the data to the given container.

    Declaration
    public static VisitResult DeserializeFromPath<TContainer>(string path, ref TContainer container)
    Parameters
    Type Name Description
    String path

    The file path to read from.

    TContainer container

    The container to deserialize data in to.

    Returns
    Type Description
    VisitResult
    Type Parameters
    Name Description
    TContainer

    The type to deserialize.

    DeserializeFromStream<TContainer>(Stream)

    Deserializes the given stream and returns a new instance of the container.

    Declaration
    public static TContainer DeserializeFromStream<TContainer>(Stream stream)
        where TContainer : new()
    Parameters
    Type Name Description
    Stream stream

    The stream to read from.

    Returns
    Type Description
    TContainer

    A new instance of the container with based on the serialized data.

    Type Parameters
    Name Description
    TContainer

    The type to deserialize.

    DeserializeFromStream<TContainer>(Stream, ref TContainer)

    Deserializes the given stream and writes the data to the given container.

    Declaration
    public static VisitResult DeserializeFromStream<TContainer>(Stream stream, ref TContainer container)
    Parameters
    Type Name Description
    Stream stream

    The stream to read from.

    TContainer container

    The container to deserialize data in to.

    Returns
    Type Description
    VisitResult
    Type Parameters
    Name Description
    TContainer

    The type to deserialize.

    DeserializeFromString<TContainer>(String)

    Deserializes the given json string and returns a new instance of the container.

    Declaration
    public static TContainer DeserializeFromString<TContainer>(string jsonString)
        where TContainer : new()
    Parameters
    Type Name Description
    String jsonString

    The json data as a string.

    Returns
    Type Description
    TContainer

    A new instance of the container with based on the serialized data.

    Type Parameters
    Name Description
    TContainer

    The type to deserialize.

    DeserializeFromString<TContainer>(String, ref TContainer)

    Deserializes the given json string and writes the data to the given container.

    Declaration
    public static VisitResult DeserializeFromString<TContainer>(string jsonString, ref TContainer container)
    Parameters
    Type Name Description
    String jsonString

    The json data as a string.

    TContainer container

    The container to deserialize data in to.

    Returns
    Type Description
    VisitResult
    Type Parameters
    Name Description
    TContainer

    The type to deserialize.

    Serialize<TContainer>(TContainer, JsonVisitor)

    Writes a property container to a json string.

    Declaration
    public static string Serialize<TContainer>(TContainer container, JsonVisitor visitor = null)
    Parameters
    Type Name Description
    TContainer container

    The container to write.

    JsonVisitor visitor

    The visitor to use. If none is provided, the default one is used.

    Returns
    Type Description
    String

    A json string.

    Type Parameters
    Name Description
    TContainer

    The type to serialize.

    Serialize<TContainer>(String, TContainer)

    Writes a property container to a file path.

    Declaration
    public static void Serialize<TContainer>(string path, TContainer target)
    Parameters
    Type Name Description
    String path

    The file path to write to.

    TContainer target

    The struct or class to serialize.

    Type Parameters
    Name Description
    TContainer

    The type to serialize.

    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023