TypeScript Interfaces to Kotlin Data Classes
Paste TypeScript interfaces and enums and get Kotlin data classes with nullable types, = null defaults for optional properties, List and Map, enum classes and optional kotlinx.serialization or Jackson annotations.
Use the tool
Why this tool exists
Android and Kotlin back-end code that consumes a TypeScript-defined API needs data classes that match the JSON property names and optionality. Typing them by hand is slow and the camelCase and snake_case names are easy to get wrong.
Optional and nullable properties become nullable Kotlin types, optional ones also get = null so the key may be missing. When a JSON key differs from the Kotlin name the converter adds @SerialName or @JsonProperty. Enum classes carry the JSON value on each entry. The output compiles with kotlinc and round-trips JSON with kotlinx.serialization and with Jackson (jackson-module-kotlin). Everything runs in your browser and nothing is uploaded.
How to use it
- Paste your TypeScript interfaces, type aliases or enums.
- Choose kotlinx.serialization, Jackson or no annotations.
- Copy the Kotlin code into your project and apply the serialization plugin if you use kotlinx.
Frequently asked questions
Which TypeScript features are supported?
Interfaces, type aliases, string enums, optional and nullable properties, unions, literals, tuples, arrays, Record, Date, extends and intersections, and JSDoc comments. Conditional and mapped types, keyof, typeof, function types and most utility generics are not supported, and the tool says so instead of guessing.
What happens to a union such as string | number?
Kotlin has no general union type, so the field becomes JsonElement (kotlinx.serialization) or Any with a comment that says it was a union. Unions of literal values such as "a" | "b" become the base type with the literal list in a comment, and a top-level string-literal type alias becomes a real enum.
Why does number become a floating point type?
TypeScript has a single number type, so the converter cannot know whether a value is an integer. It uses a floating point type by default. Switch the option or edit single fields where you know the value is whole.
How are dates handled?
Date becomes String with the ISO 8601 text that JSON.stringify produces, because kotlinx.serialization has no built-in date serializer. Change the type to Instant and add a serializer if you want a real date type.