GetSortBsonVisitor implements SortFieldExpressionVisitor<String> { public static JsonArray sortValuesAsArray(final Document document, final List<SortOption> sortOptions) { final JsonArrayBuilder builder = JsonFactory.newArrayBuilder(); sortOptions.stream() .map(SortOption::getSortExpression) .map(GetSortBsonVisitor::path) .map(seekToPath(document)) .forEach(value -> builder.add(JsonValue.of(value))); return builder.build(); } private  GetSortBsonVisitor(); static List<Bson> apply(final SortFieldExpression expression, final SortDirection sortDirection); static Document projections(final List<SortOption> sortOptions); static JsonArray sortValuesAsArray(final Document document, final List<SortOption> sortOptions); static String path(final SortFieldExpression expression); @Override String visitAttribute(final String key); @Override String visitFeatureIdProperty(final String featureId, final String property); @Override String visitSimple(final String fieldName);  }
@Test public void handlesNullValues() { final SortFieldExpression expression = new AttributeExpressionImpl("a/b/c/d/e/f/g"); final SortOption sortOption = new SortOption(expression, SortDirection.ASC); GetSortBsonVisitor.sortValuesAsArray(new Document(), Collections.singletonList(sortOption)); }