2

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.

CaptainNemo
  • 1,532
  • 2
  • 22
  • 45
  • 1
    The Firebase 2.x depended on Jackson for its JSON serialization. We're aiming to get the main use-case natively supported (with a much smaller footprint in your APK size). If you find a need for a use-case that isn't supported (yet), you can still use Jackson. See http://stackoverflow.com/questions/37547399/how-to-deserialise-a-subclass-in-firebase-using-getvaluesubclass-class/37548330#37548330 – Frank van Puffelen Jul 15 '16 at 20:38

1 Answers1

1

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?

CaptainNemo
  • 1,532
  • 2
  • 22
  • 45