Java Code Examples for org.apache.tinkerpop.shaded.jackson.core.JsonGenerator#writeStartArray()

The following examples show how to use org.apache.tinkerpop.shaded.jackson.core.JsonGenerator#writeStartArray() . 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 tinkergraph-gremlin with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(final TinkerGraph graph, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
        throws IOException {
    jsonGenerator.writeStartObject();
    jsonGenerator.writeFieldName(GraphSONTokens.VERTICES);
    jsonGenerator.writeStartArray();

    final Iterator<Vertex> vertices = graph.vertices();
    while (vertices.hasNext()) {
        serializerProvider.defaultSerializeValue(vertices.next(), jsonGenerator);
    }

    jsonGenerator.writeEndArray();
    jsonGenerator.writeFieldName(GraphSONTokens.EDGES);
    jsonGenerator.writeStartArray();

    final Iterator<Edge> edges = graph.edges();
    while (edges.hasNext()) {
        serializerProvider.defaultSerializeValue(edges.next(), jsonGenerator);
    }

    jsonGenerator.writeEndArray();
    jsonGenerator.writeEndObject();
}
 
Example 2
Source File: TinkerIoRegistryV2d0.java    From tinkergraph-gremlin with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(final TinkerGraph graph, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
        throws IOException {
    jsonGenerator.writeStartObject();
    jsonGenerator.writeFieldName(GraphSONTokens.VERTICES);
    jsonGenerator.writeStartArray();

    final Iterator<Vertex> vertices = graph.vertices();
    while (vertices.hasNext()) {
        serializerProvider.defaultSerializeValue(vertices.next(), jsonGenerator);
    }

    jsonGenerator.writeEndArray();
    jsonGenerator.writeFieldName(GraphSONTokens.EDGES);
    jsonGenerator.writeStartArray();

    final Iterator<Edge> edges = graph.edges();
    while (edges.hasNext()) {
        serializerProvider.defaultSerializeValue(edges.next(), jsonGenerator);
    }

    jsonGenerator.writeEndArray();
    jsonGenerator.writeEndObject();
}
 
Example 3
Source File: GraphSONTypeSerializerV3d0.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
public WritableTypeId writeTypePrefix(final JsonGenerator jsonGenerator, final WritableTypeId writableTypeId) throws IOException {
    if (writableTypeId.valueShape == JsonToken.START_OBJECT) {
        if (writableTypeId.forValue instanceof Map) {
            writeTypePrefix(jsonGenerator, getTypeIdResolver().idFromValueAndType(writableTypeId.forValue, getClassFromObject(writableTypeId.forValue)));
            jsonGenerator.writeStartArray();
        } else {
            jsonGenerator.writeStartObject();
        }
    } else if (writableTypeId.valueShape == JsonToken.START_ARRAY) {
        if (writableTypeId.forValue instanceof List || writableTypeId.forValue instanceof Set) {
            writeTypePrefix(jsonGenerator, getTypeIdResolver().idFromValueAndType(writableTypeId.forValue, getClassFromObject(writableTypeId.forValue)));
            jsonGenerator.writeStartArray();
        } else {
            jsonGenerator.writeStartArray();
        }
    } else if (canWriteTypeId()) {
        writeTypePrefix(jsonGenerator, getTypeIdResolver().idFromValueAndType(writableTypeId.forValue, getClassFromObject(writableTypeId.forValue)));
    } else {
        throw new IllegalStateException("Could not write prefix: shape[" + writableTypeId.valueShape + "] value[" + writableTypeId.forValue + "]");
    }

    return writableTypeId;
}
 
Example 4
Source File: TinkerIoRegistryV3d0.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(final TinkerGraph graph, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
        throws IOException {
    jsonGenerator.writeStartObject();
    jsonGenerator.writeFieldName(GraphSONTokens.VERTICES);
    jsonGenerator.writeStartArray();

    final Iterator<Vertex> vertices = graph.vertices();
    while (vertices.hasNext()) {
        serializerProvider.defaultSerializeValue(vertices.next(), jsonGenerator);
    }

    jsonGenerator.writeEndArray();
    jsonGenerator.writeFieldName(GraphSONTokens.EDGES);
    jsonGenerator.writeStartArray();

    final Iterator<Edge> edges = graph.edges();
    while (edges.hasNext()) {
        serializerProvider.defaultSerializeValue(edges.next(), jsonGenerator);
    }

    jsonGenerator.writeEndArray();
    jsonGenerator.writeEndObject();
}
 
Example 5
Source File: TinkerIoRegistryV2d0.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(final TinkerGraph graph, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
        throws IOException {
    jsonGenerator.writeStartObject();
    jsonGenerator.writeFieldName(GraphSONTokens.VERTICES);
    jsonGenerator.writeStartArray();

    final Iterator<Vertex> vertices = graph.vertices();
    while (vertices.hasNext()) {
        serializerProvider.defaultSerializeValue(vertices.next(), jsonGenerator);
    }

    jsonGenerator.writeEndArray();
    jsonGenerator.writeFieldName(GraphSONTokens.EDGES);
    jsonGenerator.writeStartArray();

    final Iterator<Edge> edges = graph.edges();
    while (edges.hasNext()) {
        serializerProvider.defaultSerializeValue(edges.next(), jsonGenerator);
    }

    jsonGenerator.writeEndArray();
    jsonGenerator.writeEndObject();
}
 
Example 6
Source File: TinkerIoRegistryV1d0.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(final TinkerGraph graph, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
        throws IOException {
    jsonGenerator.writeStartObject();

    jsonGenerator.writeFieldName(GraphSONTokens.VERTICES);
    jsonGenerator.writeStartArray();

    final Iterator<Vertex> vertices = graph.vertices();
    while (vertices.hasNext()) {
        serializerProvider.defaultSerializeValue(vertices.next(), jsonGenerator);
    }

    jsonGenerator.writeEndArray();

    jsonGenerator.writeFieldName(GraphSONTokens.EDGES);
    jsonGenerator.writeStartArray();

    final Iterator<Edge> edges = graph.edges();
    while (edges.hasNext()) {
        serializerProvider.defaultSerializeValue(edges.next(), jsonGenerator);
    }

    jsonGenerator.writeEndArray();

    jsonGenerator.writeEndObject();
}
 
Example 7
Source File: TinkerIoRegistryV1d0.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
@Override
public void serializeWithType(final TinkerGraph graph, final JsonGenerator jsonGenerator,
                              final SerializerProvider serializerProvider, final TypeSerializer typeSerializer) throws IOException {
    jsonGenerator.writeStartObject();
    jsonGenerator.writeStringField(GraphSONTokens.CLASS, TinkerGraph.class.getName());

    jsonGenerator.writeFieldName(GraphSONTokens.VERTICES);
    jsonGenerator.writeStartArray();
    jsonGenerator.writeString(ArrayList.class.getName());
    jsonGenerator.writeStartArray();

    final Iterator<Vertex> vertices = graph.vertices();
    while (vertices.hasNext()) {
        GraphSONUtil.writeWithType(vertices.next(), jsonGenerator, serializerProvider, typeSerializer);
    }

    jsonGenerator.writeEndArray();
    jsonGenerator.writeEndArray();

    jsonGenerator.writeFieldName(GraphSONTokens.EDGES);
    jsonGenerator.writeStartArray();
    jsonGenerator.writeString(ArrayList.class.getName());
    jsonGenerator.writeStartArray();

    final Iterator<Edge> edges = graph.edges();
    while (edges.hasNext()) {
        GraphSONUtil.writeWithType(edges.next(), jsonGenerator, serializerProvider, typeSerializer);
    }

    jsonGenerator.writeEndArray();
    jsonGenerator.writeEndArray();

    jsonGenerator.writeEndObject();
}
 
Example 8
Source File: GraphSONSerializersV3d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(final Tree tree, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException, JsonGenerationException {
    jsonGenerator.writeStartArray();
    final Set<Map.Entry<Element, Tree>> set = tree.entrySet();
    for (Map.Entry<Element, Tree> entry : set) {
        jsonGenerator.writeStartObject();
        jsonGenerator.writeObjectField(GraphSONTokens.KEY, entry.getKey());
        jsonGenerator.writeObjectField(GraphSONTokens.VALUE, entry.getValue());
        jsonGenerator.writeEndObject();
    }
    jsonGenerator.writeEndArray();
}
 
Example 9
Source File: GraphSONSerializersV1d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
private void writeProperties(final Vertex vertex, final JsonGenerator jsonGenerator,
                                    final SerializerProvider serializerProvider, final TypeSerializer typeSerializer) throws IOException {
    jsonGenerator.writeObjectFieldStart(GraphSONTokens.PROPERTIES);
    if (typeSerializer != null) jsonGenerator.writeStringField(GraphSONTokens.CLASS, HashMap.class.getName());

    final List<String> keys = normalize ?
            IteratorUtils.list(vertex.keys().iterator(), Comparator.naturalOrder()) : new ArrayList<>(vertex.keys());
    for (String key : keys) {
        final Iterator<VertexProperty<Object>> vertexProperties = normalize ?
                IteratorUtils.list(vertex.properties(key), Comparators.PROPERTY_COMPARATOR).iterator() : vertex.properties(key);

        if (vertexProperties.hasNext()) {
            jsonGenerator.writeArrayFieldStart(key);
            if (typeSerializer != null) {
                jsonGenerator.writeString(ArrayList.class.getName());
                jsonGenerator.writeStartArray();
            }

            while (vertexProperties.hasNext()) {
                serializerVertexProperty(vertexProperties.next(), jsonGenerator, serializerProvider, typeSerializer, normalize, false);
            }

            jsonGenerator.writeEndArray();
            if (typeSerializer != null) jsonGenerator.writeEndArray();
        }
    }

    jsonGenerator.writeEndObject();
}
 
Example 10
Source File: TraversalSerializersV3d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(final BulkSet bulkSet, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
        throws IOException {
    jsonGenerator.writeStartArray();
    for (Map.Entry entry : (Set<Map.Entry>) bulkSet.asBulk().entrySet()) {
        jsonGenerator.writeObject(entry.getKey());
        jsonGenerator.writeObject(entry.getValue());
    }
    jsonGenerator.writeEndArray();
}
 
Example 11
Source File: GraphSONTypeSerializerV2d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public WritableTypeId writeTypePrefix(final JsonGenerator jsonGenerator, final WritableTypeId writableTypeId) throws IOException {
    if (writableTypeId.valueShape == JsonToken.START_OBJECT) {
        jsonGenerator.writeStartObject();
    } else if (writableTypeId.valueShape == JsonToken.START_ARRAY) {
        jsonGenerator.writeStartArray();
    } else if (canWriteTypeId()) {
        writeTypePrefix(jsonGenerator, getTypeIdResolver().idFromValueAndType(writableTypeId.forValue, getClassFromObject(writableTypeId.forValue)));
    } else {
        throw new IllegalStateException("Could not write prefix: shape[" + writableTypeId.valueShape + "] value[" + writableTypeId.forValue + "]");
    }

    return writableTypeId;
}
 
Example 12
Source File: GraphSONSerializersV2d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(final Tree tree, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException, JsonGenerationException {
    jsonGenerator.writeStartArray();
    final Set<Map.Entry<Element, Tree>> set = tree.entrySet();
    for (Map.Entry<Element, Tree> entry : set) {
        jsonGenerator.writeStartObject();
        jsonGenerator.writeObjectField(GraphSONTokens.KEY, entry.getKey());
        jsonGenerator.writeObjectField(GraphSONTokens.VALUE, entry.getValue());
        jsonGenerator.writeEndObject();
    }
    jsonGenerator.writeEndArray();
}
 
Example 13
Source File: TinkerIoRegistryV1d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(final TinkerGraph graph, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
        throws IOException {
    jsonGenerator.writeStartObject();

    jsonGenerator.writeFieldName(GraphSONTokens.VERTICES);
    jsonGenerator.writeStartArray();

    final Iterator<Vertex> vertices = graph.vertices();
    while (vertices.hasNext()) {
        serializerProvider.defaultSerializeValue(vertices.next(), jsonGenerator);
    }

    jsonGenerator.writeEndArray();

    jsonGenerator.writeFieldName(GraphSONTokens.EDGES);
    jsonGenerator.writeStartArray();

    final Iterator<Edge> edges = graph.edges();
    while (edges.hasNext()) {
        serializerProvider.defaultSerializeValue(edges.next(), jsonGenerator);
    }

    jsonGenerator.writeEndArray();

    jsonGenerator.writeEndObject();
}
 
Example 14
Source File: TinkerIoRegistryV1d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void serializeWithType(final TinkerGraph graph, final JsonGenerator jsonGenerator,
                              final SerializerProvider serializerProvider, final TypeSerializer typeSerializer) throws IOException {
    jsonGenerator.writeStartObject();
    jsonGenerator.writeStringField(GraphSONTokens.CLASS, TinkerGraph.class.getName());

    jsonGenerator.writeFieldName(GraphSONTokens.VERTICES);
    jsonGenerator.writeStartArray();
    jsonGenerator.writeString(ArrayList.class.getName());
    jsonGenerator.writeStartArray();

    final Iterator<Vertex> vertices = graph.vertices();
    while (vertices.hasNext()) {
        GraphSONUtil.writeWithType(vertices.next(), jsonGenerator, serializerProvider, typeSerializer);
    }

    jsonGenerator.writeEndArray();
    jsonGenerator.writeEndArray();

    jsonGenerator.writeFieldName(GraphSONTokens.EDGES);
    jsonGenerator.writeStartArray();
    jsonGenerator.writeString(ArrayList.class.getName());
    jsonGenerator.writeStartArray();

    final Iterator<Edge> edges = graph.edges();
    while (edges.hasNext()) {
        GraphSONUtil.writeWithType(edges.next(), jsonGenerator, serializerProvider, typeSerializer);
    }

    jsonGenerator.writeEndArray();
    jsonGenerator.writeEndArray();

    jsonGenerator.writeEndObject();
}
 
Example 15
Source File: Geoshape.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(Geoshape value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
    jgen.writeStartObject();
    jgen.writeFieldName("type");


    switch(value.getType()) {
        case POLYGON:
            throw new UnsupportedOperationException("Ploygons are not supported");
        case BOX:
            jgen.writeString("Polygon");
            jgen.writeFieldName("coordinates");
            jgen.writeStartArray();

            jgen.writeStartArray();
            jgen.writeNumber(value.coordinates[1][0]);
            jgen.writeNumber(value.coordinates[0][0]);
            jgen.writeEndArray();

            jgen.writeStartArray();
            jgen.writeNumber(value.coordinates[1][1]);
            jgen.writeNumber(value.coordinates[0][0]);
            jgen.writeEndArray();

            jgen.writeStartArray();
            jgen.writeNumber(value.coordinates[1][1]);
            jgen.writeNumber(value.coordinates[0][1]);
            jgen.writeEndArray();

            jgen.writeStartArray();
            jgen.writeNumber(value.coordinates[1][0]);
            jgen.writeNumber(value.coordinates[0][1]);
            jgen.writeEndArray();

            jgen.writeEndArray();
            break;
        case CIRCLE:
            jgen.writeString("Circle");
            jgen.writeFieldName("radius");
            jgen.writeNumber(value.getRadius());
            jgen.writeFieldName("coordinates");
            jgen.writeStartArray();
            jgen.writeNumber(value.coordinates[1][0]);
            jgen.writeNumber(value.coordinates[0][0]);
            jgen.writeEndArray();
            break;
        case POINT:
            jgen.writeString("Point");
            jgen.writeFieldName("coordinates");
            jgen.writeStartArray();
            jgen.writeNumber(value.coordinates[1][0]);
            jgen.writeNumber(value.coordinates[0][0]);
            jgen.writeEndArray();
            break;
    }
    jgen.writeEndObject();

}
 
Example 16
Source File: GraphSONUtil.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
public static void writeStartArray(final Object o, final JsonGenerator jsonGenerator, final TypeSerializer typeSerializer) throws IOException {
    if (typeSerializer != null)
        typeSerializer.writeTypePrefixForArray(o, jsonGenerator);
    else
        jsonGenerator.writeStartArray();
}