Search in sources :

Example 1 with FilteringParserDelegate

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;
}
Also used : JsonPointerBasedFilter(com.fasterxml.jackson.core.filter.JsonPointerBasedFilter) FilteringParserDelegate(com.fasterxml.jackson.core.filter.FilteringParserDelegate) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 2 with FilteringParserDelegate

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();
}
Also used : FilteringParserDelegate(com.fasterxml.jackson.core.filter.FilteringParserDelegate)

Example 3 with FilteringParserDelegate

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();
}
Also used : FilteringParserDelegate(com.fasterxml.jackson.core.filter.FilteringParserDelegate) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 4 with FilteringParserDelegate

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();
}
Also used : FilteringParserDelegate(com.fasterxml.jackson.core.filter.FilteringParserDelegate) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 5 with FilteringParserDelegate

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();
}
Also used : FilteringParserDelegate(com.fasterxml.jackson.core.filter.FilteringParserDelegate) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Aggregations

FilteringParserDelegate (com.fasterxml.jackson.core.filter.FilteringParserDelegate)5 JsonParser (com.fasterxml.jackson.core.JsonParser)3 StreamReadException (com.fasterxml.jackson.core.exc.StreamReadException)1 JsonPointerBasedFilter (com.fasterxml.jackson.core.filter.JsonPointerBasedFilter)1