Table of Contents

Class JsonSyncSerializer

Namespace
SteamNetworkLib.Sync
Assembly
SteamNetworkLib.dll

Default JSON serializer for HostSyncVar<T> and ClientSyncVar<T>. Provides IL2CPP-compatible JSON serialization without external dependencies.

public class JsonSyncSerializer : ISyncSerializer
Inheritance
JsonSyncSerializer
Implements
Inherited Members

Remarks

Supported Types:

  • Primitives: int, long, float, double, bool, string, byte, short, uint, ulong
  • Enums: Any enum type (serialized as underlying integer value)
  • Collections: List<T>, arrays (T[]), Dictionary<string, T>
  • Custom types: Classes and structs with parameterless constructor and public properties

Requirements for Custom Types:

  1. Must have a public parameterless constructor
  2. Properties must be public with both getter and setter
  3. Property types must themselves be serializable
  4. Circular references are not supported
// Valid custom type
public class GameSettings
{
    public int MaxPlayers { get; set; } = 4;
    public string MapName { get; set; } = "default";
    public bool FriendlyFire { get; set; } = false;
    public List<string> EnabledMods { get; set; } = new();
}

// Usage
var settings = client.CreateHostSyncVar("Settings", new GameSettings());

Constructors

JsonSyncSerializer()

public JsonSyncSerializer()

Methods

CanSerialize(Type)

Checks if a type can be serialized by this serializer.

public bool CanSerialize(Type type)

Parameters

type Type

The type to check.

Returns

bool

True if the type can be serialized; otherwise, false.

Deserialize<T>(string)

Deserializes a JSON string to the specified type.

public T Deserialize<T>(string data)

Parameters

data string

The JSON string to deserialize.

Returns

T

The deserialized value.

Type Parameters

T

The type to deserialize to.

Exceptions

SyncSerializationException

Thrown when deserialization fails.

Serialize<T>(T)

Serializes a value to a JSON string.

public string Serialize<T>(T value)

Parameters

value T

The value to serialize.

Returns

string

A JSON string representation of the value.

Type Parameters

T

The type of value to serialize.

Exceptions

SyncSerializationException

Thrown when serialization fails.