Skip to content

Instantly share code, notes, and snippets.

@hlung
Created April 29, 2019 09:24
Show Gist options
  • Save hlung/d412fe6471b2982dd535150aa81caba8 to your computer and use it in GitHub Desktop.
Save hlung/d412fe6471b2982dd535150aa81caba8 to your computer and use it in GitHub Desktop.
Pokemon model classes in Kotlin
package com.raywenderlich.pokelist
import kotlinx.serialization.Serializable
@Serializable
data class Pokemon(
val name: String,
val url: String
)
@Serializable
data class Pokedex(
val pokemon_entries: List<PokemonEntry>
)
@Serializable
data class PokemonEntry(
val entry_number: Int,
val pokemon_species: Pokemon
) {
@Transient
val label: String
get() {
val name = pokemon_species.name.toUpperCase()
val id = entry_number.padding(3)
return "N°$id\t\t$name"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment