[JAVA-5019] Java driver 4.2.3 Document.getList throws ClassCastException Created: 07/Jun/23 Updated: 27/Oct/23 Resolved: 07/Jun/23 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Question | Priority: | Major - P3 |
| Reporter: | Sreenivas Gurramkonda | Assignee: | Unassigned |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Documentation Changes Summary: | 1. What would you like to communicate to the user about this feature? |
| Description |
| Comments |
| Comment by Sreenivas Gurramkonda [ 07/Jun/23 ] |
|
Thank you ross@mongodb.com for the information. I tested it and it threw exception while iteration. |
| Comment by Ross Lawley [ 07/Jun/23 ] |
Correct but once you start iterating the employees list it will throw an exception - its how Java handles casting. |
| Comment by Sreenivas Gurramkonda [ 07/Jun/23 ] |
|
Hi ross@mongodb.com thanks for your response. So it looks like I have to map the full Document to POJOs for it to work, but I have one question, the below code somehow works without any classcast exception List<Employee> employees = (List<Employee>) doc.get("employees"); can you pls give some insights on this |
| Comment by Ross Lawley [ 07/Jun/23 ] |
|
I'm closing this ticket as it is the expected behaviour. Ross |
| Comment by Ross Lawley [ 07/Jun/23 ] |
|
Thank you for reaching out. The error message describes the issue, but in simple terms you are trying to cast a List<Document> into a List<Employee> hence the exception. If you want to use POJOs you should check out the POJO documentation. Your end solution should be modelled using something like: MongoCollection<Department> - where a Department Pojo represents the full document in the DB. For future reference as this sounds like a support issue, I wanted to give you some resources to get this question answered more quickly:
All the best, Ross Lawley |
| Comment by PM Bot [ 07/Jun/23 ] |
|
Hi s.nivas123@gmail.com, thank you for reporting this issue! The team will look into it and get back to you soon. |