[英]Firebase Error: "Expected a List while deserializing, but got a class java.util.HashMap"
I had a structure in my database that worked perfectly, but then I add the following node to my database and since then I'm getting this error.我的数据库中有一个运行良好的结构,但后来我将以下节点添加到我的数据库中,从那以后我收到了这个错误。 If I delete the "commentList" node it works again.如果我删除“commentList”节点,它会再次起作用。 Why would it change from a list to a Hashmap?为什么它会从列表变为 Hashmap?
My db structure.我的数据库结构。 It worked before adding that "commentList"在添加“commentList”之前它起作用了
The code responsible for this: code负责此的代码:代码
Here the log error:这里的日志错误:
com.google.firebase.database.DatabaseException: Expected a List while deserializing, but got a class java.util.HashMap
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToParameterizedType(com.google.firebase:firebase-database@@16.0.5:233)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToType(com.google.firebase:firebase-database@@16.0.5:176)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$100(com.google.firebase:firebase-database@@16.0.5:47)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.deserialize(com.google.firebase:firebase-database@@16.0.5:580)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.deserialize(com.google.firebase:firebase-database@@16.0.5:550)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertBean(com.google.firebase:firebase-database@@16.0.5:420)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToClass(com.google.firebase:firebase-database@@16.0.5:214)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToType(com.google.firebase:firebase-database@@16.0.5:178)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$100(com.google.firebase:firebase-database@@16.0.5:47)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.deserialize(com.google.firebase:firebase-database@@16.0.5:580)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.deserialize(com.google.firebase:firebase-database@@16.0.5:550)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertBean(com.google.firebase:firebase-database@@16.0.5:420)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToClass(com.google.firebase:firebase-database@@16.0.5:214)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToType(com.google.firebase:firebase-database@@16.0.5:178)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToParameterizedType(com.google.firebase:firebase-database@@16.0.5:247)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToType(com.google.firebase:firebase-database@@16.0.5:176)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToCustomClass(com.google.firebase:firebase-database@@16.0.5:101)
at com.google.firebase.database.DataSnapshot.getValue(com.google.firebase:firebase-database@@16.0.5:239)
at com.example.xandi.whib.MainActivity$3.onDataChange(MainActivity.java:236)
at com.google.firebase.database.core.ValueEventRegistration.fireEvent(com.google.firebase:firebase-database@@16.0.5:75)
at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database@@16.0.5:63)
at com.google.firebase.database.core.view.EventRaiser$1.run(com.google.firebase:firebase-database@@16.0.5:55)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6626)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
What is causing this and how would I fix this?是什么原因造成的,我将如何解决这个问题?
You must be sure that the firebase object is array, not map, like that: firebase 您必须确保firebase对象是数组,而不是map,如下所示: firebase
I've had the same problem, the solution was check the type of object, directly in firebase database and change Map(HashMap) to Array(List) 我有同样的问题,解决方案是直接在firebase数据库中检查对象的类型,然后将Map(HashMap)更改为Array(List)
I know it's a bit late, but I'll post it for others who encounter the same issue.我知道这有点晚了,但我会为遇到同样问题的其他人发布它。 Firebase real-time database does not store collections in lists but HashMap s. Firebase 实时数据库不在列表中存储 collections 但HashMap s。 Your model property should be more like this:您的 model 属性应该更像这样:
var commentList: HashMap<String, String>? = null
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.