0

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?

majurageerthan
  • 2,169
  • 3
  • 17
  • 30
Nurseyit Tursunkulov
  • 8,012
  • 12
  • 44
  • 78

1 Answers1

0

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.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193