Details
-
Question
-
Resolution: Works as Designed
-
Major - P3
-
None
-
None
-
None
-
None
Description
while using java driver 4.2.3 with server version - 5.0.12
Document class getList method throws ClassCastExcepion below are the details.
Document in DB:
{
“name”: “hr”,
“id”: 1,
“employees”: [
{
“name”: “paul”,
“empId”: 1
},
{
“name”: “nick”,
“empId”: 2
}
]
}
Code:
public void getEmpList(){
MongoCollection<Document> coll = mongoDatabase.getCollection("Department");
try
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; }}
Output:
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)