Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to ignore/exclude fields on model on Firestore

My current goal is to send some useful data to my Firestore database. The problem is that I keep seeing the ignore fields on it.

I do not have any need to keep the boolean ‘isUserAuthenticated’ and ‘isNewUser’ on the database.

For the fields, I do not want to keep I am adding an @Exclude and I am even tried to use @ IgnoreExtraProperties on top of the class.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

An except from the model:

@IgnoreExtraProperties
class UserModel : Serializable {
    // authentication logic

    @Exclude
    var isUserAuthenticated = false

This is an excert that shows how I send it:

val profile = UserModel(
            firebaseUser.uid,
            profileName,
            firebaseUser.email,
            profileImage,
            currentLanguage,
            profileLanguages,
            0,
            100
        )

        val uidRef: DocumentReference = firebaseUser.let { usersRef.document(it.uid) }

        uidRef.get().addOnCompleteListener { uidTask: Task<DocumentSnapshot> ->
            if (uidTask.isSuccessful) {
                Log.i(TAG, "createProfileInFirestore: uidTask.isSuccessful()")
                try {
                    val document: DocumentSnapshot = uidTask.result
                    if (!document.exists()) {
                        uidRef.set(profile)
                            .addOnCompleteListener { profileCreationTask: Task<Void> ->

In Java the ignore fields worked but I am currently rewriting it in Kotlin.

>Solution :

The @Exclude annotation added in front of the public field works in Java. In Kotlin, you have to add @get:Exclude like this:

@get:Exclude
var isUserAuthenticated = false
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading