简体   繁体   English

如何在 Firebase 实时数据库中使用 ArrayLists 存储自定义 java 对象

[英]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 给出了两个错误:

  1. CustomClassMapper.convertToPlainJavaTypes CustomClassMapper.convertToPlainJavaTypes
  2. CustomClassMapper.serialize. CustomClassMapper.序列化。

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.

相关问题 如何将每个用户的数据存储在 Flutter Firebase 实时数据库中? - How to store data for each user in Flutter Firebase Realtime Database? 如何使用 javascript 在 firebase 实时数据库中使用自定义 uid 进行身份验证? - how to authenticate with custom uid in firebase realtime database using javascript? 在 Firebase 实时数据库(在 Android 中)中对 Firebase 身份验证使用自定义注册? - Using custom registration for Firebase authentication in Firebase Realtime Database (in Android)? 如何在React中更改实时数据库firebase URL - How to change firebase realtime database URL in React 如何反序列化实时 firebase 数据库的这个 hashmap - how to deserialize this hashmap of realtime firebase database 如何从firebase实时数据库中获取数据 - How to retrieve data from firebase realtime database JavaScript/Firebase:如何在 Firebase 实时数据库中存储 URL? - JavaScript/Firebase: How to store an URL in Firebase realtime DB? 如何编写 firebase 实时数据库规则以匹配根文件夹子文件夹名称与新数据自定义 uid - how to write a firebase Realtime database rule to match root folder child folders name with New Data custom uid 如何在 Firebase 实时数据库中解码这个 json? - How to decode this json in Firebase realtime Database? 如何在 Flutter 中模拟 Firebase 实时数据库? - How to mock Firebase Realtime Database in Flutter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM