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

后端 未结 2 591
灰色年华
灰色年华 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.

提交回复
热议问题