Type Registration
This page covers how to register user types in Apache Fory™ C#.
Register by Numeric Type ID
Use explicit IDs for compact and stable cross-service mapping.
Fory fory = Fory.Builder().Build();
fory.Register<User>(100);
fory.Register<Order>(101);
Register by Type Name
Use name registration when you prefer symbolic mappings. The single-string overload accepts the full user-facing name and splits it at the last dot.
Fory fory = Fory.Builder().Build();
fory.Register<User>("com.example.User");
Names without dots use an empty namespace:
fory.Register<User>("User");
The split overload is also available when you already have the namespace and final type name separately:
fory.Register<User>("com.example", "User");
Register a Custom Serializer
Fory fory = Fory.Builder().Build();
fory.Register<MyType, MyTypeSerializer>(200);
Name-based custom serializer registration is also supported:
fory.Register<MyType, MyTypeSerializer>("com.example.MyType");
Thread-Safe Registration
ThreadSafeFory exposes the same registration APIs. Registrations are propagated to all per-thread Fory instances.
using ThreadSafeFory fory = Fory.Builder().BuildThreadSafe();
fory.Register<User>(100);
fory.Register<Order>(101);
Registration Rules
- Register user-defined types on both writer and reader sides.
- Keep ID/name mappings consistent across services and languages.
- For the split overloads,
typeNamemust be non-empty and must not contain dots. - Register before high-volume serialization workloads to avoid missing type metadata.