Skip to main content
Version: 1.2.0

Type Registration

This page covers registration APIs for user-defined types.

Why Registration Is Required

User types (struct, class, enum/union, ext types) must be registered before serialization/deserialization.

If a type is missing, deserialization fails with:

  • Type not registered: ...

Register by Numeric ID

Use a stable ID shared by serializer and deserializer peers.

@ForyStruct
struct User {
var name: String = ""
var age: Int32 = 0
}

let fory = Fory()
fory.register(User.self, id: 1)

Register by Name

Fully-qualified name

try fory.register(User.self, name: "com.example.User")

name is split by the last .:

  • namespace: com.example
  • type name: User

Simple names such as User use an empty namespace. Empty names and names ending in . are invalid.

Consistency Rules

Keep registration mapping consistent across peers:

  • ID mode: same type uses same numeric ID on all peers
  • Name mode: same type uses same namespace and type name on all peers
  • Do not mix ID and name mapping for the same logical type across services

Dynamic Types and Registration

When serializing dynamic values (Any, AnyObject, any Serializer) that contain user-defined types, the concrete types must still be registered.