Hi,
while using java driver Document class getList method throws ClassCastExcepion below are the details. pls help
Document:
{
“name”: “hr”,
“id”: 1,
“employees”: [
{
“name”: “paul”,
“empId”: 1
},
{
“name”: “nick”,
“empId”: 2
}
]
}
public void getEmpList(){
MongoCollection<Document> coll = mongoDatabase.getCollection("Department");
try {
Document doc = coll.find().first();
List<Employee> employees = doc.getList("employees", Employee.class);
}catch(Exception e){
e.printStackTrace();
}
}
public class Employee{
private String name;
private Integer empId;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getEmpId() {
return empId;
}
public void setEmpId(Integer empId) {
this.empId = empId;
}
}
Exception:
java.lang.ClassCastException: List element cannot be cast to com.Employee
at org.bson.Document.constructValuesList(Document.java:383)
at org.bson.Document.getList(Document.java:350)