Search in sources :

Example 81 with JsonParser

use of com.fasterxml.jackson.core.JsonParser in project rest.li by linkedin.

the class JacksonDataCodec method readMap.

@Override
public DataMap readMap(Reader in) throws IOException {
    final Parser parser = new Parser();
    JsonParser jsonParser = null;
    try {
        jsonParser = _jsonFactory.createParser(in);
        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 82 with JsonParser

use of com.fasterxml.jackson.core.JsonParser in project rest.li by linkedin.

the class JacksonDataCodec method readList.

@Override
public DataList readList(Reader in) throws IOException {
    final Parser parser = new Parser();
    JsonParser jsonParser = null;
    try {
        jsonParser = _jsonFactory.createParser(in);
        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 83 with JsonParser

use of com.fasterxml.jackson.core.JsonParser in project orientdb by orientechnologies.

the class OGraphSONReader method inputGraph.

/**
   * Input the JSON stream data into the graph. More control over how data is streamed is provided by this method.
   *
   * @param jsonInputStream
   *          an InputStream of JSON data
   * @param bufferSize
   *          the amount of elements to hold in memory before committing a transactions (only valid for TransactionalGraphs)
   * @throws IOException
   *           thrown when the JSON data is not correctly formatted
   */
public void inputGraph(final InputStream jsonInputStream, int bufferSize, final Set<String> edgePropertyKeys, final Set<String> vertexPropertyKeys) throws IOException {
    final JsonParser jp = jsonFactory.createJsonParser(jsonInputStream);
    // if this is a transactional localGraph then we're buffering
    final BatchGraph batchGraph = BatchGraph.wrap(graph, bufferSize);
    final ElementFactory elementFactory = new GraphElementFactory(batchGraph);
    OGraphSONUtility graphson = new OGraphSONUtility(GraphSONMode.NORMAL, elementFactory, vertexPropertyKeys, edgePropertyKeys);
    long importedVertices = 0;
    long importedEdges = 0;
    while (jp.nextToken() != JsonToken.END_OBJECT) {
        final String fieldname = jp.getCurrentName() == null ? "" : jp.getCurrentName();
        if (fieldname.equals(GraphSONTokens.MODE)) {
            jp.nextToken();
            final GraphSONMode mode = GraphSONMode.valueOf(jp.getText());
            graphson = new OGraphSONUtility(mode, elementFactory, vertexPropertyKeys, edgePropertyKeys);
        } else if (fieldname.equals(GraphSONTokens.VERTICES)) {
            jp.nextToken();
            while (jp.nextToken() != JsonToken.END_ARRAY) {
                final JsonNode node = jp.readValueAsTree();
                graphson.vertexFromJson(node);
                importedVertices++;
                printStatus(jp, importedVertices, importedEdges);
            }
        } else if (fieldname.equals(GraphSONTokens.EDGES)) {
            jp.nextToken();
            while (jp.nextToken() != JsonToken.END_ARRAY) {
                final JsonNode node = jp.readValueAsTree();
                final Vertex inV = batchGraph.getVertex(OGraphSONUtility.getTypedValueFromJsonNode(node.get(GraphSONTokens._IN_V)));
                final Vertex outV = batchGraph.getVertex(OGraphSONUtility.getTypedValueFromJsonNode(node.get(GraphSONTokens._OUT_V)));
                graphson.edgeFromJson(node, outV, inV);
                importedEdges++;
                printStatus(jp, importedVertices, importedEdges);
            }
        }
    }
    jp.close();
    batchGraph.commit();
}
Also used : BatchGraph(com.tinkerpop.blueprints.util.wrappers.batch.BatchGraph) Vertex(com.tinkerpop.blueprints.Vertex) GraphElementFactory(com.tinkerpop.blueprints.util.io.graphson.GraphElementFactory) GraphSONMode(com.tinkerpop.blueprints.util.io.graphson.GraphSONMode) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonParser(com.fasterxml.jackson.core.JsonParser) ElementFactory(com.tinkerpop.blueprints.util.io.graphson.ElementFactory) GraphElementFactory(com.tinkerpop.blueprints.util.io.graphson.GraphElementFactory)

Example 84 with JsonParser

use of com.fasterxml.jackson.core.JsonParser in project orientdb by orientechnologies.

the class OGraphSONUtility method edgeFromJson.

/**
   * Creates an edge from GraphSON using settings supplied in the constructor.
   */
public Edge edgeFromJson(final InputStream json, final Vertex out, final Vertex in) throws IOException {
    final JsonParser jp = jsonFactory.createParser(json);
    final JsonNode node = jp.readValueAsTree();
    return this.edgeFromJson(node, out, in);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 85 with JsonParser

use of com.fasterxml.jackson.core.JsonParser in project orientdb by orientechnologies.

the class OGraphSONUtility method edgeFromJson.

/**
   * Creates an edge from GraphSON using settings supplied in the constructor.
   */
public Edge edgeFromJson(final String json, final Vertex out, final Vertex in) throws IOException {
    final JsonParser jp = jsonFactory.createParser(json);
    final JsonNode node = jp.readValueAsTree();
    return this.edgeFromJson(node, out, in);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonParser(com.fasterxml.jackson.core.JsonParser)

Aggregations

JsonParser (com.fasterxml.jackson.core.JsonParser)137 IOException (java.io.IOException)37 Test (org.junit.Test)35 JsonFactory (com.fasterxml.jackson.core.JsonFactory)24 StringWriter (java.io.StringWriter)17 ExtensibleJSONWriter (com.instagram.common.json.annotation.processor.support.ExtensibleJSONWriter)15 JsonNode (com.fasterxml.jackson.databind.JsonNode)14 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)13 JsonUtil.createJsonParser (com.facebook.presto.util.JsonUtil.createJsonParser)12 SqlNullable (com.facebook.presto.spi.function.SqlNullable)11 SqlType (com.facebook.presto.spi.function.SqlType)11 BaseTest (com.fasterxml.jackson.core.BaseTest)11 JsonToken (com.fasterxml.jackson.core.JsonToken)11 UTF8DataInputJsonParser (com.fasterxml.jackson.core.json.UTF8DataInputJsonParser)11 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)10 JsonParseException (com.fasterxml.jackson.core.JsonParseException)8 SimpleParseUUT (com.instagram.common.json.annotation.processor.uut.SimpleParseUUT)7 PrestoException (com.facebook.presto.spi.PrestoException)6 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)6 ScalarOperator (com.facebook.presto.spi.function.ScalarOperator)5