Firebase - No properties to serialize found on class

前端 未结 1 1953
旧时难觅i
旧时难觅i 2020-12-03 22:39

I have a class like this:

class dataModel {
    String id, name;
    Integer count;

    dataModel() {}
}

And I add data from Firebase.

相关标签:
1条回答
  • 2020-12-03 23:25

    To solve this, your class needs to implement the Serializable interface:

    class dataModel implements Serializable {}
    

    You also need to add a contructor with three arguments. Your class should look like this:

    class dataModel implements Serializable {
        private String id, name;
        private Integer count;
        @ServerTimestamp
        private Date time;
    
        dataModel() {}
    
        dataModel(String id, String name, Integer count) {
            this.id = id;
            this.name = name;
            this.count = count;
        }
    }
    

    If the date is null, it will have the server-generated timestamp. So you don't need to do set the value for it. Please also see the annotation used to mark a Date field to be populated with a server timestamp.

    Also very important, don't forget to add public getters.

    and the other requirement will be to add -keepclassmembers class com.yourcompany.models.** { *; } in proguard-rules.pro.

    As said here.

    0 讨论(0)
提交回复
热议问题