Skip to main content

External Types

FTL supports the use of external types in your FTL modules. External types are types defined in other packages or modules that are not part of the FTL module.

The primary difference is that external types are not defined in the FTL schema, and therefore serialization and deserialization of these types is not handled by FTL. Instead, FTL relies on the runtime to handle serialization and deserialization of these types.

In some cases this feature can also be used to provide custom serialization and deserialization logic for types that are not directly supported by FTL, even if they are defined in the same package as the FTL module.

To use an external type in your FTL module schema, declare a type alias over the external type:

//ftl:typealias
type FtlType external.OtherType

//ftl:typealias
type FtlType2 = external.OtherType

The external type is widened to Any in the FTL schema, and the corresponding type alias will include metadata for the runtime-specific type mapping:

typealias FtlType Any
+typemap go "github.com/external.OtherType"

Cross-Runtime Type Mappings

FTL also provides the capability to declare type mappings for other runtimes. Here's how to do it in each language:

//ftl:typealias
//ftl:typemap java "com.external.other.OtherType"
type FtlType external.OtherType

In the FTL schema, cross-runtime mappings will appear as:

typealias FtlType Any
+typemap go "github.com/external.OtherType"
+typemap java "com.external.other.OtherType"

This allows FTL to decode the type properly in other languages, for seamless interoperability across different runtimes.