【问题标题】:Storing a list of enums in firebase在firebase中存储枚举列表
【发布时间】:2016-07-15 20:09:04
【问题描述】:

我有以下代码:

public class TestClass {
     public ArrayList<ObjectTypes> list = new ArrayList<>();
     public TestClass(){
        list.add(ObjectTypes.type1);
     }
}

public enum ObjectTypes {
   type1,
   type2,
   type3,
   type4,
}

fb.child("Test").setValue(new TestClass());

其中 fb 是 DatabaseReference。

运行代码时应用程序崩溃并出现以下错误:

com.google.firebase.database.DatabaseException:没有属性 在课堂上找到序列化 对象类型

旧版 Firebase 中没有出现此问题。

【问题讨论】:

  • Firebase 2.x 依赖于 Jackson 的 JSON 序列化。我们的目标是获得原生支持的主要用例(在您的 APK 大小中占用更小的空间)。如果您发现需要(尚)不支持的用例,您仍然可以使用 Jackson。见stackoverflow.com/questions/37547399/…

标签: android serialization enums firebase firebase-realtime-database


【解决方案1】:

目前通过枚举枚举元素来解决问题(枚举一个枚举...)

在上面的例子中:

public enum ObjectTypes {
   type1(0),
   type2(1),
   type3(2),
   type4(3),
}

希望将来会添加一种更简单、更简单的方式吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-28
    • 1970-01-01
    • 1970-01-01
    • 2017-12-08
    • 2017-01-28
    相关资源
    最近更新 更多