Search in sources :

Example 41 with JsonToken

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project keycloak by keycloak.

the class RealmsConfigurationLoader method readUsers.

private static void readUsers(RealmRepresentation r, JsonParser p) throws IOException {
    JsonToken t = p.nextToken();
    if (t != JsonToken.START_ARRAY) {
        throw new RuntimeException("Error reading field 'users'. Expected array of users [" + t + "]");
    }
    t = p.nextToken();
    while (t == JsonToken.START_OBJECT) {
        UserRepresentation u = p.readValueAs(UserRepresentation.class);
        if (!started && userSkipped(u.getUsername())) {
            log.info("User skipped: " + u.getUsername());
        } else {
            enqueueCreateUser(r, u);
        }
        t = p.nextToken();
        currentUser += 1;
        // in order to short-circuit if any errors have occurred
        if (currentUser % ERROR_CHECK_INTERVAL == 0) {
            checkPendingErrors(u.getUsername());
        }
    }
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken) UserRepresentation(org.keycloak.representations.idm.UserRepresentation)

Example 42 with JsonToken

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project CzechIdMng by bcvsolutions.

the class ChangesOnSystemReportXlsxRenderer method getJsonNodeByName.

/**
 * Methods is intended to read JSON values of the renderer source file specified by its name.
 * This method searches for a field name and returns token with its value.
 * The parser is able to go through the input stream one way only.
 * Field names HAVE TO be searched in the same order they were written.
 */
JsonToken getJsonNodeByName(JsonParser jParser, String propertyName) {
    JsonToken token = null;
    try {
        do {
            String name = jParser.currentName();
            if (StringUtils.equals(name, ChangesOnSystemReportExecutor.ATTRIBUTE_NAME_JSON_KEY) && StringUtils.equals(propertyName, ChangesOnSystemReportExecutor.ATTRIBUTE_NAME_JSON_KEY)) {
                token = jParser.nextToken();
                if (token == JsonToken.START_ARRAY) {
                    return token;
                } else {
                    return null;
                }
            } else if (StringUtils.equals(name, ChangesOnSystemReportExecutor.RECORDS_JSON_KEY) && StringUtils.equals(propertyName, ChangesOnSystemReportExecutor.RECORDS_JSON_KEY)) {
                // skip to the start of array
                token = jParser.nextToken();
                do {
                    if (token == JsonToken.START_OBJECT) {
                        return token;
                    }
                    token = jParser.nextToken();
                } while (token != JsonToken.END_ARRAY);
                return null;
            } else if (name != null) {
                token = jParser.nextToken();
                if (token == JsonToken.START_OBJECT || token == JsonToken.START_ARRAY) {
                    jParser.skipChildren();
                }
            }
            token = jParser.nextToken();
        } while (!jParser.isClosed());
    } catch (Exception e) {
        return null;
    }
    return token;
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) ReportRenderException(eu.bcvsolutions.idm.rpt.api.exception.ReportRenderException)

Example 43 with JsonToken

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project Payara by payara.

the class ProgressStatusEventJsonProprietaryReader method readFrom.

@Override
public ProgressStatusEvent readFrom(final InputStream is, final String contentType) throws IOException {
    try (JsonParser jp = factory.createJsonParser(is)) {
        // sorounding object
        JsonToken token = jp.nextToken();
        // Name progress-status-event
        jp.nextToken();
        JsonToken token2 = jp.nextToken();
        if (token != JsonToken.START_OBJECT || token2 != JsonToken.START_OBJECT || !"progress-status-event".equals(jp.getCurrentName())) {
            throw new IOException("Not expected type (progress-status-event) but (" + jp.getCurrentName() + ")");
        }
        return readProgressStatusEvent(jp);
    }
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken) IOException(java.io.IOException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 44 with JsonToken

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project Payara by payara.

the class ProgressStatusDTOJsonProprietaryReader method readFrom.

@Override
public ProgressStatusDTO readFrom(final InputStream is, final String contentType) throws IOException {
    try (JsonParser jp = factory.createJsonParser(is)) {
        // sorounding object
        JsonToken token = jp.nextToken();
        // Name progress-status
        jp.nextToken();
        JsonToken token2 = jp.nextToken();
        if (token != JsonToken.START_OBJECT || token2 != JsonToken.START_OBJECT || !"progress-status".equals(jp.getCurrentName())) {
            throw new IOException("Not expected type (progress-status) but (" + jp.getCurrentName() + ")");
        }
        return readProgressStatus(jp);
    }
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken) IOException(java.io.IOException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 45 with JsonToken

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project navajo by Dexels.

the class JSONTest method simpleTest.

@Test
public void simpleTest() throws IOException {
    byte[] json_chunk1 = "{\"name\":\"El".getBytes(StandardCharsets.UTF_8);
    byte[] json_chunk2 = "vis\"}".getBytes(StandardCharsets.UTF_8);
    JsonFactory s = new JsonFactory();
    // NonBlockingJsonParser n = new NonBlockingJsonParser();
    // s.createNonBlockingByteArrayParser().getNonBlockingInputFeeder().
    NonBlockingJsonParser nbj = ((NonBlockingJsonParser) s.createNonBlockingByteArrayParser());
    nbj.feedInput(json_chunk1, 0, json_chunk1.length);
    JsonToken t = null;
    do {
        t = nbj.nextToken();
        System.err.println("t: " + t);
    } while (t != null && t != JsonToken.NOT_AVAILABLE);
    nbj.feedInput(json_chunk2, 0, json_chunk2.length);
    // nbj.endOfInput();
    do {
        t = nbj.nextToken();
        System.err.println("t: " + t);
    } while (t != null && t != JsonToken.NOT_AVAILABLE);
}
Also used : NonBlockingJsonParser(com.fasterxml.jackson.core.json.async.NonBlockingJsonParser) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonToken(com.fasterxml.jackson.core.JsonToken) Test(org.junit.Test)

Aggregations

JsonToken (com.fasterxml.jackson.core.JsonToken)251 IOException (java.io.IOException)65 JsonParser (com.fasterxml.jackson.core.JsonParser)44 ArrayList (java.util.ArrayList)27 HashMap (java.util.HashMap)25 JsonFactory (com.fasterxml.jackson.core.JsonFactory)18 JsonParseException (com.fasterxml.jackson.core.JsonParseException)15 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)9 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)6 SqlNullable (com.facebook.presto.spi.function.SqlNullable)6 SqlType (com.facebook.presto.spi.function.SqlType)6 JsonUtil.createJsonParser (com.facebook.presto.util.JsonUtil.createJsonParser)6 JsonParserHelper.assertExpectedJsonToken (com.alibaba.json.test.performance.JacksonPageModelParser.JsonParserHelper.assertExpectedJsonToken)5 InputStream (java.io.InputStream)5 LinkedHashMap (java.util.LinkedHashMap)5 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)4 ByteString (com.google.protobuf.ByteString)4 HashSet (java.util.HashSet)4 MappingJsonFactory (com.fasterxml.jackson.databind.MappingJsonFactory)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3