CaptainNemo CaptainNemo - 2 months ago 10
Android Question

Storing a list of enums in firebase

I have the following code:

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());


where fb is a DatabaseReference.

When running the code the application crashes and the following error appears:


com.google.firebase.database.DatabaseException: No properties to
serialize found on class
ObjectTypes


This problem did not appear in the old Firebase.

Answer

The problem is currently solved by enumerating the enum elements (enumerating an enum...)

In the above example:

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

Hopefully an easier less boiler plated way will be added in the future?

Comments