When you\'re making a Plain Old Java Object that\'s meant to be serialized from and deserialized to Firebase, is there a way to use the ServerValue.TIMESTAMP
va
The most common use for Server.TIMESTAMP is:
This trick saved me the hard work of handle 2 different fields for only 1 value
public class HandleTimestampFirebaseObject {
Object timestamp;
public HandleTimestampFirebaseObject() {
}
public Object getTimestamp(){
if(timestamp instanceof Double){
/* this will handle the case of AFTER fetch from backend,and
serialize to object into SharedPreferences for example ,when the
Object casting automatically into Double.
(Anyway,call (long)getTimestamp from your code who use this model*/
return ((Double) timestamp).longValue();
}
else{
return timestamp; //this handle to firebase requirement in the server side(Object needed)
}
}