FirebaseException: Failed to parse node with class in NodeUtilities.NodeFromJSON

I am using Firebase in Java. The following simple code always worked fine when user information was supposed to be updated:

final FirebaseBean_User userObject = new FirebaseBean_User(uuid, name, timestamp, points, gamesPlayed, gamesWon); mFirebaseUser.setValue(userObject, System.currentTimeMillis()); 

I used the current timestamp as a priority value to get a list of all the users who were recently online.

However, when users go offline, I would like to mark them as offline. So I added another simple line in the middle:

 final FirebaseBean_User userObject = new FirebaseBean_User(uuid, name, timestamp, points, gamesPlayed, gamesWon); mFirebaseUser.onDisconnect().setValue(userObject, USER_PRIORITY_OFFLINE); // best practice: always call onDisconnect() before the actual setValue() operation to prevent ghost data mFirebaseUser.setValue(userObject, System.currentTimeMillis()); 

And suddenly this part of the code stopped working. I get the following exception, where the calling string (465) is new in the middle:

 FATAL EXCEPTION: main com.firebase.client.FirebaseException: Failed to parse node with class class com.my.package.MultiplayerService$FirebaseBean_User at com.firebase.client.snapshot.NodeUtilities.NodeFromJSON(NodeUtilities.java:130) at com.firebase.client.OnDisconnect.setValue(OnDisconnect.java:81) at com.my.package.MultiplayerService.updateUserInformation(MultiplayerService.java:465) at com.my.package.MultiplayerService.access$4(MultiplayerService.java:461) at com.my.package.MultiplayerService$1.onDataChange(MultiplayerService.java:83) at com.firebase.client.core.ValueListenerContainer$1.run(ValueListenerContainer.java:50) at android.os.Handler.handleCallback(Handler.java:605) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4514) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557) at dalvik.system.NativeStart.main(Native Method) 

Why is this happening? Am I doing something wrong? I mean, setValue() worked fine before, now the only change is that I call it on onDisconnect() and it stops working.

(It doesnโ€™t matter if the data at this checkpoint was earlier or not.)

Here is the class that is used for reference:

 private static class FirebaseBean_User { private String uuid; private String name; private int lastlogin; private double points; private int gamesplayed; private int gameswon; private FirebaseBean_User() { } public FirebaseBean_User(String uuid, String name, int lastlogin, double points, int gamesplayed, int gameswon) { this.uuid = uuid; this.name = name; this.lastlogin = lastlogin; this.points = points; this.gamesplayed = gamesplayed; this.gameswon = gameswon; } public String getUuid() { return uuid; } public String getName() { return name; } public int getLastlogin() { return lastlogin; } public double getPoints() { return points; } public int getGamesplayed() { return gamesplayed; } public int getGameswon() { return gameswon; } @Override public boolean equals(Object o) { return (o instanceof FirebaseBean_User && ((FirebaseBean_User) o).getUuid() == this.uuid); } } 
+6
source share
2 answers

This is actually a bug in the Firebase SDK, sorry for that! In particular, this is a problem in the OnDisconnect handler. This is why it works for ref.setValue, but not ref.onDisconnect (). SetValue. I will get the fix together as soon as possible and update my answer when it is available.

Edit: try to grab the latest version of the SDK from https://www.firebase.com/docs/downloads.html It must be version 1.0.4. Let me know if you have problems.

+2
source

There seems to be a JSON parsing issue in the com.firebase.client.snapshot.NodeUtilities class.

I have not found a single document in this class, but from my experience with other serialization / parsing mechanisms, I suspect that the problem is with your FirebaseBean_User class due to the lack of empty access (as in public) constructor.

Most parsing engines end up calling the Class<?>.newInstance() method, which instantiates an object that calls an empty constructor.

So try changing:

 private FirebaseBean_User() { } 

for

 public FirebaseBean_User() { } 
0
source

Source: https://habr.com/ru/post/952326/


All Articles