adamko-dev/kotlinx-serialization-typescript-generator

Provide a tuple serializer

aSemy opened this issue · 0 comments

aSemy commented

Instead of

@Serializable
class Tiles(
  val tiles: List<Tile>,
)

@Serializable
data class Tile(
  val x: Int,
  val y: Int,
  val type: String,
)

being converted to

interface Tiles{
  tiles: Tile[];
}

interface Tile{
  x: Int;
  y: Int;
  type: string;
}

type Int = number

instead create a tuple, because it's more compact when it's encoded to JSON.

Something like...

@Serializable(with = TupleSerializer::class)
data class Tile(
  val x: Int,
  val y: Int,
  val type: String,
)
type Tile = [Int, Int, string]

This would also provide a good demonstration of how the generated Typescript is affected by custom descriptors.