case ARRAY:
return value instanceof List<?> ? (List<?>)value : null;
case OBJECT: // this is a document
if (value instanceof List<?>) return (List<?>)value;
Document doc = (Document)value;
BasicArray array = new BasicArray(doc.size());
final Iterator<String> indexIter = IndexSequence.infiniteSequence();
for (Field field : doc.fields()) {
String name = field.getName();
String index = indexIter.next();
if (!index.equals(name)) {
// The doc's field names don't match integral index values ...
return null;
}
array.addValue(value);
}
return array;
case STRING:
case INTEGER:
case NUMBER: