How to Convert cursor of get_all() into Map or list map in Rethinkdb's java driver?

StackOverflow https://stackoverflow.com/questions/23359987

  •  11-07-2023
  •  | 
  •  

Question

I have problem to convert value from get_all(array) in string(as json) or Map.

 RqlCursor cursor = r.db("test").table("x").get_all(arraylist)

when I try to fetch like

for(RqlObject o : cursor) {
        if (o instanceof java.util.List<?>) {
            List<Object> list = o.getList();
          }else if (o instanceof ListIterator<?>) {
            List<Object> list = o.getList();
            array.add(list);
          }else {
              java.util.Map<String, Object> map = o.getMap();
            }
}

None of other instances than Map catches above condition and generated error java.util.ArrayList cannot be cast to java.util.Map How can I get this Object in map or array of list map or even in json formatted string.

Was it helpful?

Solution

I got Answer myself from another source. first we have to check type with .as method. here is full code

for(RqlObject c : cursor) {
    Object o = c.as();     
    if (o instanceof java.util.List<?>) {
         List<Object> list = o.getList();
     }else if (o instanceof ListIterator<?>) {
         List<Object> list = o.getList();
     }else {
         java.util.Map<String, Object> map = o.getMap();
     }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top