Firebase - No properties to serialize found on class

10,660

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.

Share:
10,660
npk
Author by

npk

I am Nameer P K, final year Engineering Student in Computer Science and Engineering department, TKM College of Engineering, Kollam, India. I love taking on challenges, especially in programming. I have tried a little bit of everything, including Machine Learning (Keras, TensorFlow) Web development (HTML5, CSS3, php, javascript) and Android Development (Android Studio). I spend a lot of time improving my Python skills. I am an active member of IEDC, IEEE and CSI, and love organising programs and conducting workshops for our local chapters.

Updated on June 23, 2022

Comments

  • npk
    npk almost 2 years

    I have a class like this:

    class dataModel {
        String id, name;
        Integer count;
    
        dataModel() {}
    }
    

    And I add data from Firebase.

    mDatabase.addValueEventListener(mListener = new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                dataSet.add(dataSnapshot.getValue(dataModel.class));
                //...
            }
    });
    

    When I run the app as debug, there is no problem. But after it is released, app crashes with the error:

    com.google.firebase.database.DatabaseException: No properties to serialize found on class com.my.package.dataModel
    

    I have minifyEnabled true

  • Alex Mamo
    Alex Mamo over 6 years
    @Dika Just edited my answer with the other approach. Hope you reconsider upvoting the answer.
  • Dika
    Dika over 6 years
    done. sorry for late reply. And I edited your answer
  • Shruti
    Shruti over 6 years
    @AlexMamo com.google.firebase.database.DatabaseException: No properties to serialize found on class com.packagename.models.d but there is no such class in models folder
  • Kyo Huu
    Kyo Huu over 5 years
    Tks for the second last line