use of com.fasterxml.jackson.core.filter.FilteringParserDelegate in project couchbase-elasticsearch-connector by couchbase.
the class RequestFactory method getRouting.
private String getRouting(Event event, JsonPointer routingPointer) throws IOException {
requireNonNull(event);
if (routingPointer == null) {
return null;
}
final JsonParser parser = new FilteringParserDelegate(factory.createParser(event.getContent()), new JsonPointerBasedFilter(routingPointer), false, false);
if (parser.nextToken() == null) {
LOGGER.warn("Document '{}' has no field matching routing JSON pointer '{}'", redactUser(event.getKey()), routingPointer);
return null;
}
final String routingValue = parser.getValueAsString();
if (routingValue == null) {
LOGGER.warn("Document '{}' has a null or non-scalar value for routing JSON pointer '{}'", redactUser(event.getKey()), routingPointer);
return null;
}
LOGGER.trace("Routing value for {} is {}", event.getKey(), routingValue);
return routingValue;
}
use of com.fasterxml.jackson.core.filter.FilteringParserDelegate in project jackson-core by FasterXML.
the class AsyncTokenFilterTest method testFilteredNonBlockingParserAllContent.
// Passes if (but only if) all content is actually available
public void testFilteredNonBlockingParserAllContent() {
NonBlockingJsonParser nbParser = _nonBlockingParser();
FilteringParserDelegate filteredParser = new FilteringParserDelegate(nbParser, TOKEN_FILTER, Inclusion.INCLUDE_ALL_AND_PATH, true);
nbParser.feedInput(INPUT_BYTES, 0, INPUT_BYTES.length);
assertToken(JsonToken.START_OBJECT, filteredParser.nextToken());
assertToken(JsonToken.PROPERTY_NAME, filteredParser.nextToken());
assertEquals("a", nbParser.currentName());
assertToken(JsonToken.VALUE_NUMBER_INT, filteredParser.nextToken());
assertEquals(1, nbParser.getIntValue());
assertToken(JsonToken.END_OBJECT, filteredParser.nextToken());
filteredParser.close();
nbParser.close();
}
use of com.fasterxml.jackson.core.filter.FilteringParserDelegate in project jackson-core by FasterXML.
the class ParserFilterEmpty708Test method testEmptyArray.
// [core#708]
public void testEmptyArray() throws Exception {
final String json = "[ ]";
// should become: {"value":12}
JsonParser p0 = _createParser(JSON_F, json);
JsonParser p = new FilteringParserDelegate(p0, new IncludeAllFilter(), Inclusion.INCLUDE_ALL_AND_PATH, // multipleMatches
true);
assertToken(JsonToken.START_ARRAY, p.nextToken());
assertToken(JsonToken.END_ARRAY, p.nextToken());
assertNull(p.nextToken());
p.close();
}
use of com.fasterxml.jackson.core.filter.FilteringParserDelegate in project jackson-core by FasterXML.
the class ParserFilterEmpty708Test method testEmptyObject.
// [core#708]
public void testEmptyObject() throws Exception {
final String json = "{ }";
// should become: {"value":12}
JsonParser p0 = _createParser(JSON_F, json);
JsonParser p = new FilteringParserDelegate(p0, new IncludeAllFilter(), Inclusion.INCLUDE_ALL_AND_PATH, // multipleMatches
true);
assertToken(JsonToken.START_OBJECT, p.nextToken());
assertToken(JsonToken.END_OBJECT, p.nextToken());
assertNull(p.nextToken());
p.close();
}
use of com.fasterxml.jackson.core.filter.FilteringParserDelegate in project jackson-core by FasterXML.
the class AsyncTokenFilterTest method testSkipChildrenFailOnSplit.
public void testSkipChildrenFailOnSplit() {
NonBlockingJsonParser nbParser = _nonBlockingParser();
FilteringParserDelegate filteredParser = new FilteringParserDelegate(nbParser, TOKEN_FILTER, Inclusion.INCLUDE_ALL_AND_PATH, true);
nbParser.feedInput(INPUT_BYTES, 0, 5);
assertToken(JsonToken.START_OBJECT, nbParser.nextToken());
try {
nbParser.skipChildren();
fail("Should not pass!");
} catch (StreamReadException e) {
verifyException(e, "not enough content available");
verifyException(e, "skipChildren()");
}
filteredParser.close();
nbParser.close();
}
Aggregations