[英]How to store custom java objects with ArrayLists in Firebase realtime database
I am trying to store custom java objects in Firebase. These objects have ArrayLists and other object references inside them such as Location.我正在尝试将自定义 java 对象存储在 Firebase 中。这些对象内部有 ArrayLists 和其他 object 引用,例如 Location。 When I try to write these object to the database AndroidStudio gives two errors:当我尝试将这些 object 写入数据库时,AndroidStudio 给出了两个错误:
I have read that these issues are due to Firebase only supporting java objects that have default constructors, public getters and implements Serializible.我读到这些问题是由于 Firebase 仅支持 java 具有默认构造函数、公共 getter 和实现可序列化的对象。
But also (not sure) the object itself should not reference anything other than supported datattypes of Firebase which are String, Long Double, Boolean, Map<String, Object>, List<Object>.
但是(不确定)object 本身不应引用除 Firebase 支持的数据类型之外的任何内容,这些数据类型为String, Long Double, Boolean, Map<String, Object>, List<Object>.
However in my project my objects has to have ArrayList<Location>
references.但是在我的项目中,我的对象必须具有ArrayList<Location>
引用。 Any help would be much appreciated.任何帮助将非常感激。
Figured it out.弄清楚了。 I had an object which is called Route.我有一个名为 Route 的 object。 It also had a List which holds Stop objects.它还有一个包含 Stop 对象的列表。 When a stop is added to a route, a reference of the Route was also added to Stop to show that, that specific Stop exists in this Route.将停靠点添加到路线时,路线的引用也将添加到停靠点以表明该特定停靠点存在于该路线中。 However, for some reason adding Route(this) reference to Stop and adding Stop to Route(this) crashes the app.但是,出于某种原因,将 Route(this) 引用添加到 Stop 并将 Stop 添加到 Route(this) 会使应用程序崩溃。 I figure it is due to Database holding a copy of the object itself and not a reference which if allowed would result in infinite objects.我认为这是由于数据库持有 object 本身的副本而不是引用,如果允许的话将导致无限对象。
Solution: check if you have cross references between your objects.解决方案:检查您的对象之间是否有交叉引用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.