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.

When using external types:

  • The external type is typically widened to Any in the FTL schema by default
  • You can map to specific FTL types (like String) for better schema clarity
  • For JVM languages, java is always used as the runtime name in the schema, regardless of whether Kotlin or Java is used
  • Multiple +typemap annotations can be used to support cross-runtime interoperability

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

You can also specify mappings for other runtimes:

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