Android-Expected a List while deserializing, but got a class java.util.HashMap

后端 未结 5 1084
小蘑菇
小蘑菇 2021-01-18 23:07

I want to get all list of restaurants from Firebase in android.

Here is my code:

boolean delivery;
String openTime, closeTime, restaurantName;
long          


        
5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-18 23:30

    I'm not sure if this is the case, but may help others: Do not store null's on List's

    1. Firebase stores List's as Map's with index as keys, when deserialized back it detects the correlative keys and it treats it as a 'List'
    2. Null values are not stored, nulls delete the field

    So a List with a null value won't have all indexes and, when parsed, Firebase thinks that it's a Map.

    Store some kind of "empty" value instead of null and it'll work.

    Side note: if you have a map with correlative indexes it'll happen a similar error, just add some not numeric prefix on keys.

提交回复
热议问题