I have an ArrayList (json.get("pecas")) in which needs to be transformed into BasicDBList, I tried to turn on BasicDBObject before. How do I do that?
BasicDBList pecas = ((BasicDBList) json.get("pecas"));
Error
java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.mongodb.BasicDBList
Use ArrayList's .addAll() see here for details
Here is an example of converting an ArrayList to a BasicDBList. I just used String since I don't know what type your ArrayList is. Make changes accordingly.
BasicDBList dblist = new BasicDBList();
// create arraylist to use
ArrayList<String> alist = new ArrayList<String>();
alist.add("blip");
alist.add("bloop");
alist.add("blap");
dblist.addAll(alist);
System.out.println(dblist);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With