I have a model with the following structure
public class OfferModel {
private String mImageUrl;
private String mOfferCode;
private String mOfferTitle;
private String mOfferDescription;
private boolean mIsRunning;
private String mCreatorUid;
private Date mStartDate;
}
Everything else works fine on saving. It saves in Firebase Realtime database as
startDate
date: 22
day: 3
hours: 23
minutes: 20
month: 5
seconds: 50
time: 1466617850476
timezoneOffset: -330
year: 116
But when I try to retrieve it, the date gives the following error -
java.lang.ClassCastException: java.util.HashMap cannot be cast to java.util.Date
at com.localvine.models.OfferModel.<init>(OfferModel.java:37)
at com.localvine.managers.OfferManager$1.onDataChange(OfferManager.java:62)
at com.google.android.gms.internal.zzafp.zza(Unknown Source)
at com.google.android.gms.internal.zzagp.zzSu(Unknown Source)
at com.google.android.gms.internal.zzags$1.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:615)
I understand that Firebase doesn't support Java Date object, but since it's saving them in a map, how can I get back the date from that map? Is there any proper way of saving and retrieving dates in Firebase Android?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…