Firebase Database Error - Expected a Map while deserializing, but got a class java.util.ArrayList

后端 未结 2 590
灰色年华
灰色年华 2021-01-23 06:26

Edit: Figured it out, check my posted answer if you\'re having similar issues.

I know there are several questions about this issue, but none of their s

相关标签:
2条回答
  • 2021-01-23 06:52

    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++; // 1
    map.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++; // 1
    map.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.

    0 讨论(0)
  • 2021-01-23 07:01

    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:

    private Map<String, Object> mMapOne;
    

    After changing all those fileds like this, you need also to change your public setters and getters.

    Hope it helps.

    0 讨论(0)
提交回复
热议问题