简体   繁体   中英

update null field to map Firestore

I have such Object:

data class Task(var id: Int? = null,
 var cabinId: Int = 0,
 var startTime: DateTime,
 var endTime: DateTime? = null
)

when I write document it is totaly okey:

    db.collection("games").document(game.idForTitle)
        .set(game)
        .addOnSuccessListener { documentReference ->
            Log.d(TAG, "DocumentSnapshot written with ID: ${documentReference}")
        }
        .addOnFailureListener { e ->
            Log.w(TAG, "Error adding document", e)
        }

but when I try to update the endTime field it throws:

java.lang.IllegalArgumentException: Invalid data. Unsupported type: org.joda.time.DateTime (found in field endTime)

The intersting thing is that startTime filed is writen as map, but endTime is null type.

Anyone knows what to do?

The interesting thing is that startTime field is written as map, but endTime is null type.

The endTime is null because it's initialized in the constructor to be null .

var endTime: DateTime? = null

If you need the sever timestamp, change the type of the field to be of type Date , use an annotation and leave the field uninitialized as explained in my answer from the following post:

If you need to update a field, make sure that the type of that field is one of the supported data types in Firestore .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM