1

What is proper way to store Joda Date and Time in android. When I tried to save it on Firebase and got Fatal Exception. Here is the Snippet of Class of the object I want to save which says: "Serializing Arrays is not supported, please use Lists instead"

 private String mPlotId;
 private String mAreaId;
 private String mUserId;
 private int mAreaNum;
 private LocalDate mStartDate;
 private LocalDateTime mStartTime;
 private int mHour;
KENdi
  • 7,576
  • 2
  • 16
  • 31

1 Answers1

3

You can store your Joda date&times as long values by using toDateTime().getMillis():

long startDateTimeInMillis = mStartDateTime.toDateTime().getMillis();

See "Basic Write Operations" section in Firebase docs: https://firebase.google.com/docs/database/android/read-and-write

It shows what kind of stuff and how you can write to db.

Ugurcan Yildirim
  • 5,973
  • 3
  • 42
  • 73
  • The method you have mentioned prompts error stating has protected access -Ugurcan Yildirim – Jawad Hassan Soomro Aug 08 '17 at 14:48
  • Updated my answer. Try this – Ugurcan Yildirim Aug 08 '17 at 14:53
  • 3
    That's a good solution, but there's a corner case: `toDateTime` uses the JVM's default timezone to create the `DateTime`, but in case of a [Daylight Saving Time gap](https://stackoverflow.com/a/38340388/7605325), this can [throw an exception](http://www.joda.org/joda-time/apidocs/org/joda/time/LocalDateTime.html#toDateTime--). Maybe it's better to explicity use UTC, which has no DST effects: `.toDateTime(DateTimeZone.UTC)` –  Aug 08 '17 at 16:16