0

I am unable to retrieve data from the chat table using below query, can someone please take a look. thanks

Chat table format

chat
 GWyC4hqk9oRB3UxXbCV8IdqDT8M2-YazXdhCCTeF7KRQNKq2duS9qF3
 -K_89zEV7TLoeatnAToj
 action:""
 imagePath:""
 sender:"YazXdhCCTeF7KRQNKq2duS9qF3"
 text:"Hi"

 -K_8EmH2cB53KoW5qoX9
 action: ""
 imagePath: ""
 sender: "YazXdhCCTeF7KRQNKq2duS9qF3"
 text: "hi"

Query code

 mRef = new Firebase("https://moe-90cc7.firebaseio.com/chat");
        Query limitQuery = mRef.child(chatRoom).limitToLast(1);
        limitQuery.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                final Message message = dataSnapshot.getValue(Message.class);
                 textView.setText(message.getText());

            }

            @Override
            public void onCancelled(FirebaseError firebaseError) {

            }
        });

Error

Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "-K_8LQn9qhg2T-dmMmBD" (class app.chat.Message), not marked as ignorable (4 known properties: , "imagePath", "sender", "text", "action"])
                                                                  at [Source: java.io.StringReader@250d953e; line: 1, column: 26] (through reference chain: app.core.chat.Message["-K_8LQn9qhg2T-dmMmBD"])
user7327850
  • 229
  • 5
  • 15

1 Answers1

2

It seems your received data doesn't match with Message class members. The exception tell you that a member named -K_8LQn9qhg2T-dmMmBD is expected in Message class, while it seems to be the value of a member.

Try to display the content of dataSnapshot in debug mode to have a better understanding of the issue.

quent
  • 1,936
  • 1
  • 23
  • 28
  • This is indeed the cause. @user7327850: for more help in dealing with the mapping, read my Q&A: http://stackoverflow.com/questions/32108969/why-do-i-get-failed-to-bounce-to-type-when-i-turn-json-from-firebase-into-java – Frank van Puffelen Dec 29 '16 at 19:55