Preparing the data

Since the dictionary words are stored in a JSON file, we need to parse the data before saving it to a local database.

First, we'll add the class that will represent our data. In the base package (com.packt.quickstart.dictionary), we first add a new package called data. There, we put the DictionaryEntry class, which will be our data model representation:

data class DictionaryEntry(val term: String, val explanation: String)

The class has two properties: the searchable term and the term definition. It'd be also nice to have a readable string representation of this class, so we let the Kotlin compiler generate a toString method for us with its data class.

Since the file of words is around 20 MB in size, to avoid loading that ...

Get Kotlin Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.