Firebase Database Error - Expected A Map While Deserializing, But Got A Class Java.util.arraylist
Solution 1:
Alright, figured it out. If anyone reading this has this problem and are using incremented ints/longs/whatever that get converted to strings, you must add some characters to the converted int. Firebase apparently converts these keys back into non-Strings if it can be converted.
For example, if you do something like this:
int inc = 0;
inc++; // 1map.put(String.valueOf(inc), someList);
Firebase interprets that key as 1 instead of "1".
So, to force Fb to intepret as a string, do something like this:
int inc = 0;
inc++; // 1map.put(String.valueOf(inc) + "_key", someList);
And everything works out perfectly. Obviously if you also need to read those Strings back to ints, just split the string with "[_]" and you're good to go.
Solution 2:
The main issue is that you are using a List
instead of a Map
. As your error said, while deserializing it is expectig a Map
but is found an ArrayList
.
So in order to solve this problem youd need to change all the lists in your model with maps like this:
privateMap<String, Object> mMapOne;
After changing all those fileds like this, you need also to change your public setters
and getters
.
Hope it helps.
Post a Comment for "Firebase Database Error - Expected A Map While Deserializing, But Got A Class Java.util.arraylist"