use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project ksql by confluentinc.
the class ArrayContainsKudf method jsonStringArrayContains.
private boolean jsonStringArrayContains(Object searchValue, String jsonArray) {
JsonToken valueType = getType(searchValue);
try (JsonParser parser = JSON_FACTORY.createParser(jsonArray)) {
if (parser.nextToken() != START_ARRAY) {
return false;
}
while (parser.currentToken() != null) {
JsonToken token = parser.nextToken();
if (token == null) {
return searchValue == null;
}
if (token == END_ARRAY) {
return false;
}
parser.skipChildren();
if (valueType == token) {
final Matcher matcher = matchers.get(valueType);
if (matcher != null && matcher.matches(parser, searchValue)) {
return true;
}
}
}
} catch (IOException e) {
throw new KsqlException("Invalid JSON format: " + jsonArray, e);
}
return false;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project OpenTripPlanner by opentripplanner.
the class PointSet method validateGeoJson.
/**
* Examines a JSON stream to see if it matches the expected OTPA format.
* TODO improve the level of detail of validation. Many files pass the validation and then crash the load function.
*
* @return the number of features in the collection if it's valid, or -1 if
* it doesn't fit the OTPA format.
*/
public static int validateGeoJson(InputStream is) {
int n = 0;
JsonFactory f = new JsonFactory();
try {
JsonParser jp = f.createParser(is);
JsonToken current = jp.nextToken();
if (current != JsonToken.START_OBJECT) {
LOG.error("Root of OTPA GeoJSON should be a JSON object.");
return -1;
}
// Iterate over the key:value pairs in the top-level JSON object
while (jp.nextToken() != JsonToken.END_OBJECT) {
String key = jp.getCurrentName();
current = jp.nextToken();
if (key.equals("features")) {
if (current != JsonToken.START_ARRAY) {
LOG.error("Error: GeoJSON features are not in an array.");
return -1;
}
// Iterate over the features in the array
while (jp.nextToken() != JsonToken.END_ARRAY) {
n += 1;
jp.skipChildren();
}
} else {
// ignore all other keys except features
jp.skipChildren();
}
}
if (n == 0)
// JSON has no features
return -1;
return n;
} catch (Exception ex) {
LOG.error("Exception while validating GeoJSON: {}", ex);
return -1;
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project OpenTripPlanner by opentripplanner.
the class BitSetDeserializer method deserialize.
@Override
public BitSet deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
BitSet ret = new BitSet();
int i = 0;
JsonToken token;
while (!JsonToken.END_ARRAY.equals(token = jsonParser.nextValue())) {
if (JsonToken.VALUE_TRUE.equals(token))
ret.set(i);
i++;
}
return ret;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project vespa by vespa-engine.
the class JsonBenchmark method benchmarkJacksonStreaming.
private static long benchmarkJacksonStreaming(byte[] json, int numIterations) {
long count = 0;
JsonFactory jsonFactory = new JsonFactory();
try {
for (int i = 0; i < numIterations; i++) {
JsonParser jsonParser = jsonFactory.createParser(json);
JsonToken array = jsonParser.nextToken();
for (JsonToken token = jsonParser.nextToken(); !JsonToken.END_ARRAY.equals(token); token = jsonParser.nextToken()) {
if (JsonToken.FIELD_NAME.equals(token) && "weight".equals(jsonParser.getCurrentName())) {
token = jsonParser.nextToken();
count += jsonParser.getLongValue();
}
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return count;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project vespa by vespa-engine.
the class JsonReader method next.
public DocumentOperation next() {
switch(state) {
case AT_START:
JsonToken t = nextToken(parser);
expectArrayStart(t);
state = ReaderState.READING;
break;
case END_OF_FEED:
return null;
case READING:
break;
}
Optional<DocumentParseInfo> documentParseInfo;
try {
documentParseInfo = parseDocument();
} catch (IOException r) {
// Jackson is not able to recover from structural parse errors
state = END_OF_FEED;
throw new RuntimeException(r);
}
if (!documentParseInfo.isPresent()) {
state = END_OF_FEED;
return null;
}
VespaJsonDocumentReader vespaJsonDocumentReader = new VespaJsonDocumentReader();
DocumentOperation operation = vespaJsonDocumentReader.createDocumentOperation(getDocumentTypeFromString(documentParseInfo.get().documentId.getDocType(), typeManager), documentParseInfo.get());
operation.setCondition(TestAndSetCondition.fromConditionString(documentParseInfo.get().condition));
return operation;
}
Aggregations