Supported Types
This page lists the Dart types you can use in Fory messages, and flags where you need to be careful for cross-language compatibility.
Built-in Primitive Types
The following Dart types serialize directly without any special handling:
| Dart type | Cross-language notes |
|---|---|
bool | Direct mapping |
int | Serialized as 64-bit by default. Use wrappers or @Int32Type etc. when the peer expects a narrower integer |
double | Maps to 64-bit float. Use Float32 wrapper when the peer expects 32-bit |
String | Direct mapping |
Uint8List | Binary blob |
List, Set, Map | Supported; element types must also be supported |
DateTime | Use Timestamp or LocalDate wrappers for explicit semantics |
Integer Wrappers
Dart int is 64-bit at runtime. If the peer language expects a 32-bit integer (Java int, Go int32, C# int) and you send a Dart int, the deserialization may fail or silently truncate.
Use an integer wrapper class to pin the exact wire width:
final Int8 tiny = Int8(-1); // 8-bit signed
final Int16 shortValue = Int16(7); // 16-bit signed
final Int32 age = Int32(36); // 32-bit signed — matches Java int, C# int, Go int32
final UInt8 flags = UInt8(255); // 8-bit unsigned
final UInt16 port = UInt16(65535); // 16-bit unsigned
final UInt32 count = UInt32(4000000000); // 32-bit unsigned
Each wrapper clamps the stored value to the target bit width.
Floating-Point Wrappers
Dart double maps to 64-bit float. If the peer uses a 32-bit float, use a wrapper:
Float32— 32-bit float (matches Javafloat, C#float, Gofloat32)Float16— half-precision, for specialized numeric payloads
Time and Date Types
Avoid sending raw DateTime across languages — time zone handling and epoch differences vary. Use the explicit wrappers instead:
Timestamp— a UTC instant with nanosecond precision (seconds + nanoseconds)LocalDate— a calendar date without time or time zone
final now = Timestamp.fromDateTime(DateTime.now().toUtc());
final birthday = LocalDate(1990, 12, 1);
Structs and Enums
Annotate classes with @ForyStruct() and run build_runner to make them serializable. Enums in the same file are included automatically.
@ForyStruct()
class User {
User();
String name = '';
Int32 age = Int32(0); // use Int32 when peers expect a 32-bit integer
}
See Code Generation.
Collections
Fory supports List<T>, Set<T>, and Map<K, V>. Element and key types must also be serializable types. Avoid using mutable objects as map keys.
Compatibility Tip
When in doubt about whether a Dart type will match what the peer expects, use the explicit wrapper types. Guessing the wrong numeric width is one of the most common cross-language bugs.