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 namespace + type name registration when you prefer symbolic mappings.
Fory fory = Fory.Builder().Build();
fory.Register<User>("com.example", "User");
You can also use the short overload:
fory.Register<User>("User");
Register a Custom Serializer
Fory fory = Fory.Builder().Build();
fory.Register<MyType, MyTypeSerializer>(200);
Namespace-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 runtimes.
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.
- Register before high-volume serialization workloads to avoid runtime misses.