Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

firebase

I'm using Firebase in Java. The following simple code has always worked fine when users' information had 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 the priority value so that I can get a list of all users that have been online recently.

However, when users go offline, I would like to mark them as offline. Thus, I added one simple line again 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 piece of code stopped working. I'm getting the following Exception, where the causing line (465) is the new one 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 does that happen? Am I doing anything wrong? I mean, setValue() worked fine before, now the only change is that I call it on onDisconnect() as well and it stops working.

(It does not matter if there has been data at that reference point before 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);
    }

}
like image 357
caw Avatar asked Aug 23 '13 01:08

caw


1 Answers

This is in fact a bug in the Firebase SDK, sorry about that! Specifically, it's an issue in the OnDisconnect handler. That's why it works for ref.setValue, but not ref.onDisconnect().setValue. I'll get a fix together ASAP and update my answer once it's available.

Edit: try grabbing the latest SDK from https://www.firebase.com/docs/downloads.html It should be version 1.0.4. Let me know if you continue to have trouble.

like image 145
Greg Soltis Avatar answered Oct 06 '22 00:10

Greg Soltis