Example usage for com.fasterxml.jackson.core JsonToken END_ARRAY

List of usage examples for com.fasterxml.jackson.core JsonToken END_ARRAY

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonToken END_ARRAY.

Prototype

JsonToken END_ARRAY

To view the source code for com.fasterxml.jackson.core JsonToken END_ARRAY.

Click Source Link

Document

END_ARRAY is returned when encountering ']' which signals ending of an Array value

Usage

From source file:org.talend.dataprep.api.dataset.LightweightExportableDataSetUtils.java

/**
 * Reads token of the specified JsonParser and returns a list of column metadata.
 *
 * @param jsonParser the jsonParser whose next tokens are supposed to represent a list of column metadata
 * @return The column metadata parsed from JSON parser.
 * @throws IOException In case of JSON exception related error.
 *//*w  w w  .  j  av  a  2  s.c  o m*/
private static List<ColumnMetadata> parseAnArrayOfColumnMetadata(JsonParser jsonParser) throws IOException {
    try {
        List<ColumnMetadata> columns = new ArrayList<>();
        // skip the array beginning [
        jsonParser.nextToken();
        while (jsonParser.nextToken() != JsonToken.END_ARRAY && !jsonParser.isClosed()) {
            ColumnMetadata columnMetadata = jsonParser.readValueAs(ColumnMetadata.class);
            columns.add(columnMetadata);
        }
        if (columns.isEmpty()) {
            throw new IllegalArgumentException(
                    "No column metadata has been retrieved when trying to parse the retrieved data set.");
        }
        return columns;
    } catch (IOException e) {
        throw new IOExceptionWithCause("Unable to parse and retrieve the list of column metadata", e);
    }
}

From source file:org.talend.dataprep.api.dataset.LightweightExportableDataSetUtils.java

private static LightweightExportableDataSet parseRecords(JsonParser jsonParser, RowMetadata rowMetadata,
        String joinOnColumn) throws IOException {
    try {//  www  .ja va  2s .  com
        LightweightExportableDataSet lookupDataset = new LightweightExportableDataSet();
        lookupDataset.setMetadata(rowMetadata);
        jsonParser.nextToken();
        while (jsonParser.nextToken() != JsonToken.END_ARRAY && !jsonParser.isClosed()) {
            Map<String, String> values = jsonParser.readValueAs(Map.class);
            lookupDataset.addRecord(values.get(joinOnColumn), values);
        }
        if (lookupDataset.isEmpty()) {
            throw new IllegalArgumentException(
                    "No lookup record has been retrieved when trying to parse the retrieved data set.");
        }
        return lookupDataset;
    } catch (IOException e) {
        throw new IOExceptionWithCause("Unable to parse and retrieve the records of the data set", e);
    }
}