protected Object getValue()

in src/main/java/software/amazon/documentdb/jdbc/DocumentDbResultSet.java [125:154]


    protected Object getValue(final int columnIndex) throws SQLException {
        final ResultSetMetaData metadata = getMetaData();
        final String path = paths.get(columnIndex - 1);

        if (path == null || path.isEmpty()) {
            throw SqlError.createSQLException(LOGGER, SqlState.DATA_EXCEPTION,
                    SqlError.CANNOT_RETRIEVE_COLUMN, metadata.getColumnName(columnIndex));
        }

        final String[] segmentedPath = path.split("\\.");
        Object segmentValue = current.get(segmentedPath[0]);
        for (int j = 1; j < segmentedPath.length && segmentValue instanceof Document; j++) {
            segmentValue = ((Document) segmentValue).get(segmentedPath[j]);
        }
        // Apache converters cannot handle the following types, must be specifically converted.
        if (segmentValue instanceof Binary) {
            return ((Binary) segmentValue).getData();
        }
        if (segmentValue instanceof Document) {
            return ((Document) segmentValue).toJson();
        }
        if (segmentValue instanceof List) {
            final List<?> modifiedList = ((List<?>) segmentValue)
                    .stream()
                    .map(o1 -> o1 instanceof Document ? ((Document) o1).toJson() : o1)
                    .collect(Collectors.toList());
            return modifiedList.toString();
        }
        return segmentValue;
    }