Android Local Database Tricks with Kotlin and ObjectBox.

Ryan Godlonton-Shaw
3 min readMar 9, 2019

For those of you looking for a simple way to store large chunks of JSON data into a local database in Android, then look no further. There are so many times when we come across offline requirements of accessing big chunks of data from a REST online database and saving it locally for offline use later but do not want to go through with writing excessive and large amounts of boilerplate code to do it and we would like a way to do this simply and most effectively.

Here I present a really simple and easy way to save large data into your local DB without relying on Shared Preferences or the need to do lengthy ORM mapping or creating custom converters for your data classes. Shared Preferences was one option but it is normally only used for saving small pockets of data like settings — the other downside is that if large data is saved into Shared Preferences it takes a really long time to access the Shared Preferences data again.

So welcome to ObjectBox. What is ObjectBox?

ObjectBox is a really cool super fast object-oriented mobile database that persists objects, built uniquely for IoT and Mobile devices. It lets you avoid many repetitive tasks and offers a simple interface to your data. It seems to have been adopted by the Android engineering world really well so far replacing SQLite databases quite rapidly.

Below is a quick and simple solution for developers looking to rapidly setup ObjectBox and also have a way to store data quickly without having to write custom converters for each and every data object in their DB.

So let’s begin — Firstly install ObjectBox.

Add it to your project in your root build.gradle.

In your app build.gradle module add this.