Firebaseexception: Failed to Bounce to type

Asked

Viewed 99 times

2

I’m trying to requisition an app for firebase. I can save data in the database normally, but when retrieving it, I find the following error:

06-20 12:07:15.151 28158-28158/sgk.com.br.sgk E/Androidruntime: FATAL EXCEPTION: main Process: sgk.com.br.sgk, PID: 28158 com.firebase.client.Firebaseexception: Failed to Bounce to type at com.firebase.client.DataSnapshot.getValue(Datasnapshot.java:183) at sgk.com.br.sgk.Activity.Greattrainsactivity$1.onDataChange(Greattrainsactivity.java:65) com.firebase.client.core.Valueeventregistration.fireEvent(Valueeventregistration.java:45) at com.firebase.client.core.view.DataEvent.fire(Dataevent.java:45) at com.firebase.client.core.view.Eventraiser$1.run(Eventraiser.java:38) at android.os.Handler.handleCallback(Handler.java:746) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.Activitythread.main(Activitythread.java:5443) at java.lang.reflect.Method.invoke(Native Method) at com.android.Internal.os.Zygoteinit$Methodandargscaller.run(Zygoteinit.java:728) at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:618) Caused by: com.fasterxml.Jackson.databind.exc.Unrecognizedpropertyexception: Unrecognized field "vdsrXOFXRZbAfmoEQ3WEVB1GDDa2" (class sgk.com.br.sgk.Others.Train), not marked as ignorable (2 known properties: "Description", "local"]) at [Source: java.io.Stringreader@ab 8ad7; line: 1, column: 34] (through Reference chain: sgk.com.br.sgk.Others.Train["vdsrXOFXRZbAfmoEQ3WEVB1GDa2"]) at com.fasterxml.Jackson.databind.Deserializationcontext.reportUnknownProperty(Deserializationcontext.java:555) at com.fasterxml.Jackson.databind.deser.std.Stddeserializer.handleUnknownProperty(Stddeserializer.java:708) with.fasterxml.Jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(Beandeserializerbase.java:1160) at com.fasterxml.Jackson.databind.deser.BeanDeserializer.deserializeFromObject(Beandeserializer.java:315) with.fasterxml.Jackson.databind.deser.BeanDeserializer.deserialize(Beandeserializer.java:121) at com.fasterxml.Jackson.databind.Objectmapper. _readMapAndClose(Objectmapper.java:2888) at com.fasterxml.Jackson.databind.Objectmapper.readValue(Objectmapper.java:2034) at com.firebase.client.DataSnapshot.getValue(Datasnapshot.java:181) at sgk.com.br.sgk.Activity.Greattrainsactivity$1.onDataChange(Greattrainsactivity.java:65)  com.firebase.client.core.Valueeventregistration.fireEvent(Valueeventregistration.java:45)  at com.firebase.client.core.view.DataEvent.fire(Dataevent.java:45)  at com.firebase.client.core.view.Eventraiser$1.run(Eventraiser.java:38)  at android.os.Handler.handleCallback(Handler.java:746)  at android.os.Handler.dispatchMessage(Handler.java:95)  at android.os.Looper.loop(Looper.java:148)  at android.app.Activitythread.main(Activitythread.java:5443)  at java.lang.reflect.Method.invoke(Native Method)

This is my code

Firebase.setAndroidContext(this);
        Firebase ref = new Firebase(Constants.FIREBASE_URL);

        ref.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot snapshot) {
                for (DataSnapshot postSnapshot : snapshot.getChildren()) {
                    //Getting the data from snapshot
                    Train train = postSnapshot.getValue(Train.class);
                    //Adding it to a string
                    String string = "Local: " + train.getLocal() + "\nDescrição: " + train.getDescription() + "\n\n";
                    //Displaying it on textview
                    textViewPersons.setText(string);
                }
            }

            @Override
            public void onCancelled(FirebaseError firebaseError) {
                System.out.println("The read failed: " + firebaseError.getMessage());
            }
        });

And this is my POJO

public class Train {

private String local;
private String description;

public Train() {
}

public String getLocal() {
    return local;
}

public void setLocal(String local) {
    this.local = local;
}

public String getDescription() {
    return description;
}

public void setDescription(String description) {
    this.description = description;
}
  • Gee, vei, new technology, I took the implementation because I had problems, published the new verses without it, I’ll wait a few more days to update with the api... if Voce solve, post here, can help and much...

3 answers

1

It seems to me that Firebase uses Jackson by default to convert Json/String objects and vice versa, so it is mandatory for Jackson that its class has the implementation of the toString() method for string representation of the object (if you don’t have a specific parser as your code shows).

Example:

@Override
  public String toString() { return "Train{local='"+local+“', description='"+description+"'}”; }
  • 1

    Thanks for your help. But in the firebase documentation there was nothing related to this and I discovered that the problem was another, as I explained in my reply. Thank you!

1


You are trying to access the firebase root node, it has other nodes besides Train. The return is telling you that it is not possible to transform the json object received from firebase to your Pojo. That is, your pojo only waits on the Train but is getting all nodes that are on the same level as Train, in case the users node. You must navigate to the son of the root node that would be his Train node. the method used for this Child("node name")

Try this:

ref.child("Train").addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot snapshot) {
                for (DataSnapshot postSnapshot : snapshot.getChildren()) {
                    //Getting the data from snapshot
                    Train train = postSnapshot.getValue(Train.class);
                    //Adding it to a string
                    String string = "Local: " + train.getLocal() + "\nDescrição: " + train.getDescription() + "\n\n";
                    //Displaying it on textview
                    textViewPersons.setText(string);
                }
            }

            @Override
            public void onCancelled(FirebaseError firebaseError) {
                System.out.println("The read failed: " + firebaseError.getMessage());
            }
        });

0

I figured out what the problem was.

The Json from the Firebase database had users registered in the application. Follow the code

    {
  "Train" : {
    "description" : "dbdjem",
    "local" : "shsusn"
  },
  "users" : {
    "f01dfa18-54ac-41ea-97ff-97d0e40b872b" : {
      "email" : "[email protected]"
    },
    "vdsrXOFXRZbAfmoEQ3WEVB1GDDa2" : {
      "email" : "[email protected]"
    }
  }
}

Just delete users from the database and leave only that part of json and the application worked normally.

   {
  "Train" : {
    "description" : "hdjdjdnd",
    "local" : "udjdjdjd"
  }
}
  • Cool Leonardo! Thank you for putting the answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.