3232import java .util .Map ;
3333import java .util .Objects ;
3434import java .util .Optional ;
35+ import java .util .function .Function ;
3536import java .util .logging .Level ;
3637import java .util .logging .Logger ;
3738import java .util .stream .Collectors ;
39+ import java .util .stream .StreamSupport ;
3840
3941import static java .util .Collections .singletonMap ;
4042import static java .util .stream .Collectors .toList ;
43+ import static java .util .stream .Collectors .toMap ;
4144import static java .util .stream .StreamSupport .stream ;
4245
4346/**
@@ -49,6 +52,9 @@ public final class ArangoDBUtil {
4952 public static final String ID = "_id" ;
5053 public static final String REV = "_rev" ;
5154
55+ private static final Function <Object , String > KEY_DOCUMENT = d -> cast (d ).getName ();
56+ private static final Function <Object , Object > VALUE_DOCUMENT = d -> cast (d ).get ();
57+
5258 private static final ValueWriter WRITER = ValueWriterDecorator .getInstance ();
5359
5460
@@ -140,7 +146,20 @@ private static Object convert(Value value) {
140146 Document document = Document .class .cast (val );
141147 return singletonMap (document .getName (), convert (document .getValue ()));
142148 }
149+ if (isSudDocument (val )) {
150+ return StreamSupport .stream (Iterable .class .cast (val ).spliterator (), false )
151+ .collect (toMap (KEY_DOCUMENT , VALUE_DOCUMENT ));
152+ }
143153 return val ;
144154 }
145155
156+ private static boolean isSudDocument (Object value ) {
157+ return value instanceof Iterable && StreamSupport .stream (Iterable .class .cast (value ).spliterator (), false ).
158+ allMatch (d -> org .jnosql .diana .api .document .Document .class .isInstance (d ));
159+ }
160+
161+ private static org .jnosql .diana .api .document .Document cast (Object document ) {
162+ return org .jnosql .diana .api .document .Document .class .cast (document );
163+ }
164+
146165}
0 commit comments