Firebase Firestore toObject() with Kotlin

In my case I was getting a NullPointerException because there wasn't a default constructor. Using a data class with default values fixed the error.

data class Message(
        val messageId : String = "",
        val userId : String = "",
        val userName : String = "",
        val text : String = "",
        val imageUrl : String? = null,
        val date : String = ""
)

You forgot to include the public constructor with arguments, or you can also just use a data class with default values, it should be enough:

data class MyObject(var foo: String = "")