Search in sources :

Example 1 with JsonParser

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project jvm-serializers by eishay.

the class StdJacksonDataBind method deserializeItems.

@Override
@SuppressWarnings("unchecked")
public T[] deserializeItems(InputStream in, int numberOfItems) throws IOException {
    T[] result = (T[]) new Object[numberOfItems];
    JsonParser parser = constructParser(in);
    for (int i = 0; i < numberOfItems; ++i) {
        result[i] = (T) reader.readValue(parser, type);
    }
    parser.close();
    return result;
}
Also used : JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 2 with JsonParser

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project elasticsearch by elastic.

the class ElasticsearchHostsSniffer method readHosts.

private List<HttpHost> readHosts(HttpEntity entity) throws IOException {
    try (InputStream inputStream = entity.getContent()) {
        JsonParser parser = jsonFactory.createParser(inputStream);
        if (parser.nextToken() != JsonToken.START_OBJECT) {
            throw new IOException("expected data to start with an object");
        }
        List<HttpHost> hosts = new ArrayList<>();
        while (parser.nextToken() != JsonToken.END_OBJECT) {
            if (parser.getCurrentToken() == JsonToken.START_OBJECT) {
                if ("nodes".equals(parser.getCurrentName())) {
                    while (parser.nextToken() != JsonToken.END_OBJECT) {
                        JsonToken token = parser.nextToken();
                        assert token == JsonToken.START_OBJECT;
                        String nodeId = parser.getCurrentName();
                        HttpHost sniffedHost = readHost(nodeId, parser, this.scheme);
                        if (sniffedHost != null) {
                            logger.trace("adding node [" + nodeId + "]");
                            hosts.add(sniffedHost);
                        }
                    }
                } else {
                    parser.skipChildren();
                }
            }
        }
        return hosts;
    }
}
Also used : InputStream(java.io.InputStream) HttpHost(org.apache.http.HttpHost) ArrayList(java.util.ArrayList) JsonToken(com.fasterxml.jackson.core.JsonToken) IOException(java.io.IOException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 3 with JsonParser

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project rest.li by linkedin.

the class JacksonDataCodec method stringToList.

@Override
public DataList stringToList(String input) throws IOException {
    final Parser parser = new Parser();
    JsonParser jsonParser = null;
    try {
        jsonParser = _jsonFactory.createParser(input);
        return parser.parse(jsonParser, DataList.class);
    } catch (IOException e) {
        throw e;
    } finally {
        closeJsonParserQuietly(jsonParser);
    }
}
Also used : IOException(java.io.IOException) JsonParser(com.fasterxml.jackson.core.JsonParser) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 4 with JsonParser

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project rest.li by linkedin.

the class JacksonDataCodec method stringToMap.

@Override
public DataMap stringToMap(String input) throws IOException {
    final Parser parser = new Parser();
    JsonParser jsonParser = null;
    try {
        jsonParser = _jsonFactory.createParser(input);
        return parser.parse(jsonParser, DataMap.class);
    } catch (IOException e) {
        throw e;
    } finally {
        closeJsonParserQuietly(jsonParser);
    }
}
Also used : IOException(java.io.IOException) JsonParser(com.fasterxml.jackson.core.JsonParser) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 5 with JsonParser

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project rest.li by linkedin.

the class JacksonDataCodec method parse.

/**
   * Reads an {@link InputStream} and parses its contents into a list of Data objects.
   *
   * @param in provides the {@link InputStream}
   * @param mesg provides the {@link StringBuilder} to store validation error messages,
   *             such as duplicate keys in the same {@link DataMap}.
   * @param locationMap provides where to store the mapping of a Data object
   *                    to its location in the in the {@link InputStream}. may be
   *                    {@code null} if this mapping is not needed by the caller.
   *                    This map should usually be an {@link IdentityHashMap}.
   * @return the list of Data objects parsed from the {@link InputStream}.
   * @throws IOException if there is a syntax error in the input.
   */
public List<Object> parse(InputStream in, StringBuilder mesg, Map<Object, DataLocation> locationMap) throws IOException {
    final Parser parser = new Parser(true);
    JsonParser jsonParser = null;
    try {
        jsonParser = _jsonFactory.createParser(in);
        return parser.parse(jsonParser, mesg, locationMap);
    } catch (IOException e) {
        throw e;
    } finally {
        closeJsonParserQuietly(jsonParser);
    }
}
Also used : IOException(java.io.IOException) JsonParser(com.fasterxml.jackson.core.JsonParser) JsonParser(com.fasterxml.jackson.core.JsonParser)

Aggregations

JsonParser (com.fasterxml.jackson.core.JsonParser)577 KriptonRuntimeException (com.abubusoft.kripton.exception.KriptonRuntimeException)258 JacksonWrapperParser (com.abubusoft.kripton.persistence.JacksonWrapperParser)258 KriptonJsonContext (com.abubusoft.kripton.KriptonJsonContext)257 ArrayList (java.util.ArrayList)166 IOException (java.io.IOException)121 JsonFactory (com.fasterxml.jackson.core.JsonFactory)71 Test (org.junit.Test)54 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)47 JsonNode (com.fasterxml.jackson.databind.JsonNode)45 HashSet (java.util.HashSet)43 JsonToken (com.fasterxml.jackson.core.JsonToken)40 LinkedHashSet (java.util.LinkedHashSet)38 HashMap (java.util.HashMap)32 LinkedList (java.util.LinkedList)26 JsonParseException (com.fasterxml.jackson.core.JsonParseException)23 JsonUtil.createJsonParser (com.facebook.presto.util.JsonUtil.createJsonParser)21 DeserializationContext (com.fasterxml.jackson.databind.DeserializationContext)20 StringWriter (java.io.StringWriter)20 InputStream (java.io.InputStream)19