use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project curiostack by curioswitch.
the class ParseSupport method parseObjectStart.
/**
* Checks the current token is '{' and advances past it. For parsing the beginning of JSON objects
* ({@link Message}s and {@link java.util.Map}s).
*/
public static void parseObjectStart(JsonParser parser) throws IOException {
JsonToken json = parser.currentToken();
if (json != JsonToken.START_OBJECT) {
throw new InvalidProtocolBufferException("Expected an object but found: " + json);
}
parser.nextToken();
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project curiostack by curioswitch.
the class ParseSupport method parseString.
/**
* Parsers a string value out of the input.
*/
public static String parseString(JsonParser parser) throws IOException {
JsonToken json = parser.currentToken();
String result = null;
try {
result = parser.getValueAsString();
} catch (IOException e) {
// Fall through
}
if (result == null) {
throw new InvalidProtocolBufferException("Not a string value: " + json);
}
return result;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project cytoscape-impl by cytoscape.
the class CyTransformerReaderImpl method readCompositeFilter.
@SuppressWarnings({ "unchecked", "rawtypes" })
private void readCompositeFilter(JsonParser parser, CompositeFilter composite) throws IOException {
JsonToken firstToken = parser.nextToken();
if (firstToken == JsonToken.END_OBJECT) {
return;
}
if (firstToken != JsonToken.FIELD_NAME) {
throw new IOException("Expected: " + JsonToken.FIELD_NAME + ". Got: " + firstToken);
}
assertEquals(FilterIO.TRANSFORMERS_FIELD, parser.getCurrentName());
assertEquals(JsonToken.START_ARRAY, parser.nextToken());
while (true) {
Filter filter = (Filter) readTransformer(parser);
if (filter == null) {
break;
}
composite.append(filter);
}
assertEquals(JsonToken.END_ARRAY, parser.getCurrentToken());
assertNextToken(parser, JsonToken.END_OBJECT);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project cytoscape-impl by cytoscape.
the class CyTransformerReaderImpl method readTransformer.
private Transformer<?, ?> readTransformer(JsonParser parser) throws IOException {
JsonToken firstToken = parser.nextToken();
if (firstToken == JsonToken.END_ARRAY) {
return null;
}
if (firstToken != JsonToken.START_OBJECT) {
throw new IOException("Expected: " + JsonToken.START_OBJECT + ". Got: " + firstToken);
}
assertField(parser, FilterIO.ID_FIELD);
String id = parser.nextTextValue();
assertField(parser, FilterIO.PARAMETERS_FIELD);
assertNextToken(parser, JsonToken.START_OBJECT);
Transformer<?, ?> transformer = transformerManager.createTransformer(id);
if (transformer == null && !id.contains(".")) {
transformer = transformerManager.createTransformer("org.cytoscape." + id);
}
if (transformer == null) {
throw new IOException("Unrecognized id: '" + id + "'");
}
Map<String, Object> parameters = readParameters(parser);
assertEquals(JsonToken.END_OBJECT, parser.getCurrentToken());
FilterIO.applyParameters(parameters, transformer);
if (transformer instanceof CompositeFilter) {
readCompositeFilter(parser, (CompositeFilter<?, ?>) transformer);
} else if (transformer instanceof SubFilterTransformer) {
SubFilterTransformer<?, ?> sft = (SubFilterTransformer<?, ?>) transformer;
readCompositeFilter(parser, sft.getCompositeFilter());
} else {
assertNextToken(parser, JsonToken.END_OBJECT);
}
return transformer;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project components by Talend.
the class DatasetWritePayload method createStreamToReadData.
private static Iterator<IndexedRecord> createStreamToReadData(JsonParser parser, ObjectMapper mapper, Schema schema, InputStream input) throws IOException {
JsonToken dataFieldToken = parser.nextToken();
isTrue(FIELD_NAME == dataFieldToken, invalidInputMessage(FIELD_NAME, dataFieldToken));
isTrue(Objects.equals(DATA_FIELD_NAME, parser.getText()), invalidInputMessage(DATA_FIELD_NAME, parser.getText()));
JsonToken dataArrayStartToken = parser.nextToken();
isTrue(START_ARRAY == dataArrayStartToken, invalidInputMessage(START_ARRAY, dataArrayStartToken));
JsonToken firstDataObjectStartToken = parser.nextToken();
isTrue(START_OBJECT == firstDataObjectStartToken, invalidInputMessage(START_OBJECT, firstDataObjectStartToken));
Iterator<ObjectNode> objectNodeIterator = parser.readValuesAs(ObjectNode.class);
GenericDatumReader<GenericRecord> reader = new GenericDatumReader<>(schema);
return new Iterator<IndexedRecord>() {
@Override
public boolean hasNext() {
return objectNodeIterator.hasNext();
}
@Override
public IndexedRecord next() {
try {
ObjectNode next = objectNodeIterator.next();
return reader.read(null, DecoderFactory.get().jsonDecoder(schema, mapper.writeValueAsString(next)));
} catch (IOException e) {
throw new RuntimeException("Error while reading avro data.", e);
}
}
};
}
Aggregations