1

Today I tried to move to the new (Google)Firebase.

Not only is the API different, but also the way data is stored in the database is different. For instance, numbers (Double) saved in the database as "7.5" is not parsed correctly (identified as string) when it was originally written to the database this way by the old Firebase. Had to manually rewrite the database for Doubles ("7.5" to 7.5), Booleans ("true" to true) etc.

Now I come upon a new issue. I get an error when trying to write enums to the database:

FATAL EXCEPTION: main Process: com.aayaffe.sailingracecoursemanager, PID: 21845 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aayaffe.sailingracecoursemanager/com.aayaffe.sailingracecoursemanager.map.GoogleMapsActivity}: com.google.firebase.database.DatabaseException: No properties to serialize found on class com.aayaffe.sailingracecoursemanager.communication.ObjectTypes at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2658) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2723) at android.app.ActivityThread.access$900(ActivityThread.java:172) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:5832) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) Caused by: com.google.firebase.database.DatabaseException: No properties to serialize found on class com.aayaffe.sailingracecoursemanager.communication.ObjectTypes at com.google.android.gms.internal.zzaix$zza.(Unknown Source) at com.google.android.gms.internal.zzaix.zzj(Unknown Source) at com.google.android.gms.internal.zzaix.zzaw(Unknown Source) at com.google.android.gms.internal.zzaix.zzaD(Unknown Source) at com.google.android.gms.internal.zzaix$zza.zzaE(Unknown Source) at com.google.android.gms.internal.zzaix.zzaw(Unknown Source) at com.google.android.gms.internal.zzaix.zzav(Unknown Source) at com.google.firebase.database.DatabaseReference.zza(Unknown Source) at com.google.firebase.database.DatabaseReference.setValue(Unknown Source) at com.aayaffe.sailingracecoursemanager.communication.Firebase.writeBoatObject(Firebase.java:135) at com.aayaffe.sailingracecoursemanager.map.GoogleMapsActivity$5.run(GoogleMapsActivity.java:284) at com.aayaffe.sailingracecoursemanager.map.GoogleMapsActivity.onStart(GoogleMapsActivity.java:407) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1234) at android.app.Activity.performStart(Activity.java:6258) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2621) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2723)  at android.app.ActivityThread.access$900(ActivityThread.java:172)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:145)  at android.app.ActivityThread.main(ActivityThread.java:5832)  at java.lang.reflect.Method.invoke(Native Method)  at java.lang.reflect.Method.invoke(Method.java:372)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) 

Ideas?

--EDITED--

Code:

public enum ObjectTypes {
  Gate,
  Other
}     
FirebaseDatabase.getInstance().getReferenceFromUrl(c.getString(R.string.firebase_base_url)).child("test").setValue(ObjectTypes.Gate);
CaptainNemo
  • 1,532
  • 2
  • 22
  • 45
  • I don't we changed anything about the way we store numbers. But it could of course aways be that a bug was introduced along the way. Can you share a minimal amount of code with which I can reproduce this problem? – Frank van Puffelen May 21 '16 at 00:20
  • @FrankvanPuffelen added a minimal code example in the question – CaptainNemo May 21 '16 at 08:47
  • Thanks. I'll look into it. But it'll probably take some time, because we're somewhat overwhelmed by the number of questions. – Frank van Puffelen May 21 '16 at 14:52

1 Answers1

3

My feeling with Firebase 9.0.0 is that it adheres much more to the documentation.

Json supported formats are ( String, Long, Double, Boolean, Map, List) - from firebase docs.

The previous SDK - using Jackson - was more flexible. Eg. A String could easily be parsed to a Long in the model, as long as it's a numeric. Lists could be parsed into Arrays [], and so on... Not anymore.

This may be good or not. In one hand you lose flexibility but in the other it makes you more conscious on the defined model and what you actually deploy to the network.

With respect to enums this post may help.

Community
  • 1
  • 1
rmarau
  • 388
  • 1
  • 4
  • 12