Java Code Examples for org.apache.tinkerpop.shaded.jackson.databind.DeserializationContext#readValue()

The following examples show how to use org.apache.tinkerpop.shaded.jackson.databind.DeserializationContext#readValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TinkerIoRegistryV3d0.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
public TinkerGraph deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    final Configuration conf = new BaseConfiguration();
    conf.setProperty("gremlin.tinkergraph.defaultVertexPropertyCardinality", "list");
    final TinkerGraph graph = TinkerGraph.open(conf);

    while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
        if (jsonParser.getCurrentName().equals("vertices")) {
            while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                if (jsonParser.currentToken() == JsonToken.START_OBJECT) {
                    final DetachedVertex v = (DetachedVertex) deserializationContext.readValue(jsonParser, Vertex.class);
                    v.attach(Attachable.Method.getOrCreate(graph));
                }
            }
        } else if (jsonParser.getCurrentName().equals("edges")) {
            while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                if (jsonParser.currentToken() == JsonToken.START_OBJECT) {
                    final DetachedEdge e = (DetachedEdge) deserializationContext.readValue(jsonParser, Edge.class);
                    e.attach(Attachable.Method.getOrCreate(graph));
                }
            }
        }
    }

    return graph;
}
 
Example 2
Source File: TraversalSerializersV3d0.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
public Traverser deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    long bulk = 1;
    Object v = null;

    while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
        if (jsonParser.getCurrentName().equals(GraphSONTokens.BULK)) {
            jsonParser.nextToken();
            bulk = deserializationContext.readValue(jsonParser, Long.class);
        } else if (jsonParser.getCurrentName().equals(GraphSONTokens.VALUE)) {
            jsonParser.nextToken();
            v = deserializationContext.readValue(jsonParser, Object.class);
        }
    }

    return new DefaultRemoteTraverser<>(v, bulk);
}
 
Example 3
Source File: GraphSONSerializersV3d0.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
public Property deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    String key = null;
    Object value = null;
    while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
        if (jsonParser.getCurrentName().equals(GraphSONTokens.KEY)) {
            jsonParser.nextToken();
            key = jsonParser.getText();
        } else if (jsonParser.getCurrentName().equals(GraphSONTokens.VALUE)) {
            jsonParser.nextToken();
            value = deserializationContext.readValue(jsonParser, Object.class);
        }
    }

    return new DetachedProperty<>(key, value);
}
 
Example 4
Source File: TinkerIoRegistryV2d0.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
public TinkerGraph deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    final Configuration conf = new BaseConfiguration();
    conf.setProperty("gremlin.tinkergraph.defaultVertexPropertyCardinality", "list");
    final TinkerGraph graph = TinkerGraph.open(conf);

    while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
        if (jsonParser.getCurrentName().equals("vertices")) {
            while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                if (jsonParser.currentToken() == JsonToken.START_OBJECT) {
                    final DetachedVertex v = (DetachedVertex) deserializationContext.readValue(jsonParser, Vertex.class);
                    v.attach(Attachable.Method.getOrCreate(graph));
                }
            }
        } else if (jsonParser.getCurrentName().equals("edges")) {
            while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                if (jsonParser.currentToken() == JsonToken.START_OBJECT) {
                    final DetachedEdge e = (DetachedEdge) deserializationContext.readValue(jsonParser, Edge.class);
                    e.attach(Attachable.Method.getOrCreate(graph));
                }
            }
        }
    }

    return graph;
}
 
Example 5
Source File: TraversalSerializersV3d0.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
public TextP deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    String predicate = null;
    String value = null;

    while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
        if (jsonParser.getCurrentName().equals(GraphSONTokens.PREDICATE)) {
            jsonParser.nextToken();
            predicate = jsonParser.getText();
        } else if (jsonParser.getCurrentName().equals(GraphSONTokens.VALUE)) {
            jsonParser.nextToken();
            value = deserializationContext.readValue(jsonParser, String.class);
        }
    }

    try {
        return (TextP) TextP.class.getMethod(predicate, String.class).invoke(null, value);
    } catch (final Exception e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
 
Example 6
Source File: TraversalSerializersV2d0.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
public Traverser deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    long bulk = 1;
    Object v = null;

    while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
        if (jsonParser.getCurrentName().equals(GraphSONTokens.BULK)) {
            jsonParser.nextToken();
            bulk = deserializationContext.readValue(jsonParser, Long.class);
        } else if (jsonParser.getCurrentName().equals(GraphSONTokens.VALUE)) {
            jsonParser.nextToken();
            v = deserializationContext.readValue(jsonParser, Object.class);
        }
    }

    return new DefaultRemoteTraverser<>(v, bulk);
}
 
Example 7
Source File: TraversalSerializersV2d0.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
public Bytecode.Binding deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    String k = null;
    Object v = null;

    while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
        if (jsonParser.getCurrentName().equals(GraphSONTokens.KEY)) {
            jsonParser.nextToken();
            k = jsonParser.getText();
        } else if (jsonParser.getCurrentName().equals(GraphSONTokens.VALUE)) {
            jsonParser.nextToken();
            v = deserializationContext.readValue(jsonParser, Object.class);
        }
    }
    return new Bytecode.Binding<>(k, v);
}
 
Example 8
Source File: TraversalSerializersV2d0.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
public TextP deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    String predicate = null;
    String value = null;

    while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
        if (jsonParser.getCurrentName().equals(GraphSONTokens.PREDICATE)) {
            jsonParser.nextToken();
            predicate = jsonParser.getText();
        } else if (jsonParser.getCurrentName().equals(GraphSONTokens.VALUE)) {
            jsonParser.nextToken();
            value = deserializationContext.readValue(jsonParser, String.class);
        }
    }

    try {
        return (TextP) TextP.class.getMethod(predicate, String.class).invoke(null, value);
    } catch (final Exception e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
 
Example 9
Source File: SchemaTable.java    From sqlg with MIT License 5 votes vote down vote up
@Override
public SchemaTable deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException {
    org.apache.tinkerpop.shaded.jackson.core.JsonToken jsonToken = jsonParser.nextToken();
    Preconditions.checkState(org.apache.tinkerpop.shaded.jackson.core.JsonToken.VALUE_STRING == jsonToken);
    String schema = deserializationContext.readValue(jsonParser, String.class);
    jsonToken = jsonParser.nextToken();
    Preconditions.checkState(org.apache.tinkerpop.shaded.jackson.core.JsonToken.FIELD_NAME == jsonToken);
    jsonToken = jsonParser.nextToken();
    Preconditions.checkState(org.apache.tinkerpop.shaded.jackson.core.JsonToken.VALUE_STRING == jsonToken);
    String table = deserializationContext.readValue(jsonParser, String.class);
    jsonToken = jsonParser.nextToken();
    Preconditions.checkState(org.apache.tinkerpop.shaded.jackson.core.JsonToken.END_OBJECT == jsonToken);
    return SchemaTable.of(schema, table);
}
 
Example 10
Source File: RecordId.java    From sqlg with MIT License 5 votes vote down vote up
@Override
public RecordId deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException {
    @SuppressWarnings("unchecked") final Map<String, Object> data = deserializationContext.readValue(jsonParser, Map.class);
    SchemaTable schemaTable = (SchemaTable) data.get("schemaTable");
    if (data.get("id") instanceof Long) {
        return RecordId.from(schemaTable, (Long) data.get("id"));
    } else {
        @SuppressWarnings("unchecked")
        List<Comparable> identifiers = new ArrayList<>((List<Comparable>) data.get("id"));
        return RecordId.from(schemaTable, identifiers);
    }
}
 
Example 11
Source File: TraversalSerializersV3d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public BulkSet deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {

    final BulkSet<Object> bulkSet = new BulkSet<>();

    while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
        final Object key = deserializationContext.readValue(jsonParser, Object.class);
        jsonParser.nextToken();
        final Long val = deserializationContext.readValue(jsonParser, Long.class);
        bulkSet.add(key, val);
    }

    return bulkSet;
}
 
Example 12
Source File: AbstractObjectDeserializer.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public T deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    jsonParser.nextToken();

    // This will automatically parse all typed stuff.
    final Map<String, Object> mapData = deserializationContext.readValue(jsonParser, LinkedHashMap.class);

    return createObject(mapData);
}
 
Example 13
Source File: HugeResource.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Override
public HugeResource deserialize(JsonParser parser,
                                DeserializationContext ctxt)
                                throws IOException {
    HugeResource res = new HugeResource();
    while (parser.nextToken() != JsonToken.END_OBJECT) {
        String key = parser.getCurrentName();
        if (key.equals("type")) {
            if (parser.nextToken() != JsonToken.VALUE_NULL) {
                res.type = ctxt.readValue(parser, ResourceType.class);
            } else {
                res.type = null;
            }
        } else if (key.equals("label")) {
            if (parser.nextToken() != JsonToken.VALUE_NULL) {
                res.label = parser.getValueAsString();
            } else {
                res.label = null;
            }
        } else if (key.equals("properties")) {
            if (parser.nextToken() != JsonToken.VALUE_NULL) {
                @SuppressWarnings("unchecked")
                Map<String, Object> prop = ctxt.readValue(parser,
                                                          Map.class);
                res.properties = prop;
            } else {
                res.properties = null;
            }
        }
    }
    res.checkFormat();
    return res;
}
 
Example 14
Source File: GraphSONSerializersV3d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public TraversalMetrics deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    final Map<String, Object> traversalMetricsData = deserializationContext.readValue(jsonParser, Map.class);

    return new DefaultTraversalMetrics(
            Math.round((Double) traversalMetricsData.get(GraphSONTokens.DURATION) * 1000000),
            (List<MutableMetrics>) traversalMetricsData.get(GraphSONTokens.METRICS)
    );
}
 
Example 15
Source File: GraphSONSerializersV3d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public TraversalExplanation deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    final Map<String, Object> explainData = deserializationContext.readValue(jsonParser, Map.class);
    final String originalTraversal = explainData.get(GraphSONTokens.ORIGINAL).toString();
    final List<Triplet<String, String, String>> intermediates = new ArrayList<>();
    final List<Map<String,Object>> listMap = (List<Map<String,Object>>) explainData.get(GraphSONTokens.INTERMEDIATE);
    for (Map<String,Object> m : listMap) {
        intermediates.add(Triplet.with(m.get(GraphSONTokens.STRATEGY).toString(),
                m.get(GraphSONTokens.CATEGORY).toString(),
                m.get(GraphSONTokens.TRAVERSAL).toString()));
    }

    return new ImmutableExplanation(originalTraversal, intermediates);
}
 
Example 16
Source File: GraphSONSerializersV2d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public TraversalExplanation deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    final Map<String, Object> explainData = deserializationContext.readValue(jsonParser, Map.class);
    final String originalTraversal = explainData.get(GraphSONTokens.ORIGINAL).toString();
    final List<Triplet<String, String, String>> intermediates = new ArrayList<>();
    final List<Map<String,Object>> listMap = (List<Map<String,Object>>) explainData.get(GraphSONTokens.INTERMEDIATE);
    for (Map<String,Object> m : listMap) {
        intermediates.add(Triplet.with(m.get(GraphSONTokens.STRATEGY).toString(),
                m.get(GraphSONTokens.CATEGORY).toString(),
                m.get(GraphSONTokens.TRAVERSAL).toString()));
    }

    return new ImmutableExplanation(originalTraversal, intermediates);
}
 
Example 17
Source File: JavaUtilSerializersV3d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public Map deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    final Map<Object,Object> m = new LinkedHashMap<>();

    while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
        final Object key = deserializationContext.readValue(jsonParser, Object.class);
        jsonParser.nextToken();
        final Object val = deserializationContext.readValue(jsonParser, Object.class);
        m.put(key, val);
    }

    return m;
}
 
Example 18
Source File: BitsyGraphSONModule.java    From bitsy with Apache License 2.0 4 votes vote down vote up
@Override
public UUID deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    jsonParser.nextToken();
    final String uuidStr = deserializationContext.readValue(jsonParser, String.class);
    return UUID.fromString(uuidStr);
}
 
Example 19
Source File: CustomId.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public CustomId deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    final Map<String, Object> data = deserializationContext.readValue(jsonParser, Map.class);
    return new CustomId((String) data.get("cluster"), (UUID) data.get("elementId"));
}
 
Example 20
Source File: SchemaTable.java    From sqlg with MIT License 4 votes vote down vote up
@Override
public SchemaTable deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException {
    @SuppressWarnings("unchecked")
    final Map<String, Object> data = deserializationContext.readValue(jsonParser, Map.class);
    return SchemaTable.of((String)data.get("schema"), (String) data.get("table"));
}