Data Schemas Generation From Existing DataFrame
Special utility functions that generate code of useful Kotlin definitions (returned as a String) based on the current DataFrame schema.
generateDataClasses
Generates Kotlin data classes corresponding to the DataFrame schema (including all nested DataFrame columns and column groups).
Useful when you want to:
Work with the data as regular Kotlin data classes.
Convert a dataframe to instantiated data classes with
df.toListOf<DataClassType>().Work with data classes serialization.
Extract structured types for further use in your application.
Arguments
markerName:String?— The base name to use for generated data classes.
Ifnull, uses theTtype argument ofDataFramesimple name.
Default:null.extensionProperties:Boolean– Whether to generate extension properties in addition tointerfacedeclarations.
Useful if you don't use the compiler plugin, otherwise they are not needed; the compiler plugin, notebooks, and older Gradle/KSP plugin generate them automatically. Default:false.visibility:MarkerVisibility– Visibility modifier for the generated declarations.
Default:MarkerVisibility.IMPLICIT_PUBLIC.useFqNames:Boolean– Iftrue, fully qualified type names will be used in generated code.
Default:false.nameNormalizer:NameNormalizer– Strategy for converting column names (with spaces, underscores, etc.) to Kotlin-style identifiers. Generated properties will still refer to columns by their actual name using the@ColumnNameannotation. Default:NameNormalizer.default.
Returns
CodeString– A value class wrapper forString, containing
the generated Kotlin code ofdata classdeclarations and optionally extension properties.
Examples
Output:
Add these classes to your project and convert the DataFrame to a list of typed objects:
generateInterfaces
Generates @DataSchema interfaces for this DataFrame (including all nested DataFrame columns and column groups) as Kotlin interfaces.
This is useful when working with the compiler plugin in cases where the schema cannot be inferred automatically from the source.
Arguments
markerName:String?— The base name to use for generated interfaces.
Ifnull, uses theTtype argument ofDataFramesimple name.
Default:null.extensionProperties:Boolean– Whether to generate extension properties in addition tointerfacedeclarations.
Useful if you don't use the compiler plugin, otherwise they are not needed; the compiler plugin, notebooks, and older Gradle/KSP plugin generate them automatically. Default:false.visibility:MarkerVisibility– Visibility modifier for the generated declarations.
Default:MarkerVisibility.IMPLICIT_PUBLIC.useFqNames:Boolean– Iftrue, fully qualified type names will be used in generated code.
Default:false.nameNormalizer:NameNormalizer– Strategy for converting column names (with spaces, underscores, etc.) to Kotlin-style identifiers. Generated properties will still refer to columns by their actual name using the@ColumnNameannotation. Default:NameNormalizer.default.
Returns
CodeString– A value class wrapper forString, containing
the generated Kotlin code of@DataSchemainterfaces without extension properties.
Examples
Output:
By adding these interfaces to your project with the compiler plugin enabled,
you'll gain full support for the extension properties API and type-safe operations.
Use cast to apply the generated schema to a DataFrame: