I have a class like this:
class dataModel {
String id, name;
Integer count;
dataModel() {}
}
And I add data from Firebase.
To solve this, your class needs to implement the Serializable interface:
class dataModel implements Serializable {}
You also need to add a contructor with three arguments. Your class should look like this:
class dataModel implements Serializable {
private String id, name;
private Integer count;
@ServerTimestamp
private Date time;
dataModel() {}
dataModel(String id, String name, Integer count) {
this.id = id;
this.name = name;
this.count = count;
}
}
If the date is null
, it will have the server-generated timestamp. So you don't need to do set the value for it. Please also see the annotation
used to mark a Date
field to be populated with a server timestamp.
Also very important, don't forget to add public getters
.
and the other requirement will be to add -keepclassmembers class com.yourcompany.models.** { *; }
in proguard-rules.pro.
As said here.