0
{  
"patients": {
"-Kx5vuRqItEF-7kAgVWy": {
    "name": "name1",
    "age": "27",
    "graphData": {
        "-K5knK9j8EfUHS7AesFw": {
            "date": "16/12/2015",
            "graphList": "[...]"
        }
    }
},
"-Kx5vuRqItEF-7kAgVWy": {
    "name": "name1",
    "age": "27",
    "graphData": {
        "-K5knK9j8EfUHS7AesFw": {
            "date": "16/12/2015",
            "graphList": "[...]"
        },
        "--K5knNeBFoLrjWnZshfL": {
            "date": "12/12/2015",
            "graphList": "[...]"
        },

    }
  }
 }
}

The PatientView is Java object and it contains another nested Graph Object

public class PatientView {
private String name;
private String age;
private boolean gender;
private float height;
private String phone;
private Object bdate;

private String image;

private ArrayList<Graph> graphData;

public PatientView() {
}
}

Graph Object: which has date and ArrayList object

public class Graph implements Serializable {
private Object graphDate;
private ArrayList<Double> graphList;

// Empty constructor needed for firebase
public Graph() {

}

public Graph(Object graphDate, ArrayList<Double> graphList) {
    this.graphDate = graphDate;
    this.graphList = graphList;
}
}

and reading the values by firebase addChildEventListen

public void onChildAdded(DataSnapshot dataSnapshot, String s) {
            if (dataSnapshot != null && dataSnapshot.getValue() != null) {

                PatientView p = dataSnapshot.getValue(PatientView.class);

                patients.add(p);
                patientIdsFromServer.add(dataSnapshot.getKey());
                recyclerView.scrollToPosition(patients.size() - 1);
                mAdapter.notifyItemInserted(patients.size() - 1);
            }
        }

but getting error like

Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token at [Source: java.io.StringReader@2ced7c6a; line: 1, column: 62] (through reference chain: com.iitb.openmrs.openmrsfinal.ui.Adapter.PatientView["graphData"])

The problem is the when I am pushing data to graphData child it id's are generated so the the schema is not matching with the Graph Object. I searched for is there any way to suppress the id's while reading data not have not found anything.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Vikram
  • 31
  • 5
  • Instead of posting a link to an image of the JSON data, please include the text of that JSON data in your question. Doing so ensures we don't have to keep two tabs open to compare the data and code. In addition it allows us to more easily copy/paste the JSON into our own database for testing (or into an answer). – Frank van Puffelen Dec 17 '15 at 15:54

1 Answers1

0

The problem here is the data in graphData is not an Array. Firebase has no native support for arrays. If you store an array, it really gets stored as an “object” with integers as the key names and since your key is not integer you cannot use it as Array.

You should check out this SO answer.

Community
  • 1
  • 1
Prashant Solanki
  • 660
  • 5
  • 10