我试图使用以下代码持久化自定义对象:
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference();DatabaseReference curWorkoutExercisesRef = databaseReference.child("workouts") .child(mCurrentWorkout.getID()) .child("workoutExercises");WorkoutExercise we = new WorkoutExercise(exercise);curWorkoutExercisesRef.push().setValue(we);
这是我的目标:
public class WorkoutExercise { private String ID; private Exercise exercise; public WorkoutExercise() {} // getters, setters, other methods // ...}public class Exercise { private String ID; private String Title; private List<BodyPart> bodyParts; public Exercise() {} // getters, setters, other methods // ...}public class BodyPart { private String ID; private String name; public BodyPart() {} // getters, setters, other methods // ...}
每次我收到此错误时 – com.Google.firebase.database.DatabaseException:不支持序列化数组,请改用列表.我的对象不包含任何数组,因此这个错误看起来很混乱.我找到了一种方法来修复这个错误 – 如果我将@Exclude注释添加到我的Exercise类的bodyParts列表中,一切正常,但显然不是我想要实现的.
所以似乎Firebase无法持久存在包含内部列表的对象?这里有任何简单的解决方法或最佳实践吗?谢谢!
附:我正在使用firebase-database:9.2.1
解决方法:
我设法找到导致这次崩溃的原因.我在另一台运行AndroID 5.x的设备上安装了该应用,Firebase在那里引发了一个不那么令人困惑的异常:
com.Google.firebase.database.DatabaseException: No propertIEs to serialize found on class androID.graphics.Paint$Align
似乎Firebase(与Gson不同)尝试序列化所有可能的getter,即使它们没有与全局变量(类成员/字段)直接连接,在我的特定情况下,我的一个对象包含一个返回Drawable的方法 – getDrawable() .显然,Firebase不知道如何将drawable转换为Json.
有趣的时刻(可能是Firebase SDK中的一个错误):在我运行AndroID 4.4.1的旧设备上,我仍然在同一个项目和配置中得到原始异常:
Caused by: com.Google.firebase.database.DatabaseException: Serializing Arrays is not supported, please use Lists instead
总结 以上是内存溢出为你收集整理的java – com.google.firebase.database.DatabaseException:不支持序列化数组,请改用列表全部内容,希望文章能够帮你解决java – com.google.firebase.database.DatabaseException:不支持序列化数组,请改用列表所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)