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

The following examples show how to use org.apache.tinkerpop.shaded.jackson.core.JsonGenerator#writeStringField() . 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: MetricsModule.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(Meter meter, JsonGenerator json,
                      SerializerProvider provider) throws IOException {
    json.writeStartObject();
    json.writeNumberField("count", meter.getCount());
    json.writeNumberField("m15_rate", meter.getFifteenMinuteRate() *
                                      this.rateFactor);
    json.writeNumberField("m1_rate", meter.getOneMinuteRate() *
                                     this.rateFactor);
    json.writeNumberField("m5_rate", meter.getFiveMinuteRate() *
                                     this.rateFactor);
    json.writeNumberField("mean_rate", meter.getMeanRate() *
                                       this.rateFactor);
    json.writeStringField("units", this.rateUnit);
    json.writeEndObject();
}
 
Example 2
Source File: GraphSONSerializersV1d0.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
private static void ser(final Tree tree, final JsonGenerator jsonGenerator, final TypeSerializer typeSerializer)
        throws IOException {
    jsonGenerator.writeStartObject(); 
    if (typeSerializer != null) jsonGenerator.writeStringField(GraphSONTokens.CLASS, HashMap.class.getName());
    
    Set<Map.Entry<Element, Tree>> set = tree.entrySet();
    for(Map.Entry<Element, Tree> entry : set)
    {
        jsonGenerator.writeObjectFieldStart(entry.getKey().id().toString());
        if (typeSerializer != null) jsonGenerator.writeStringField(GraphSONTokens.CLASS, HashMap.class.getName());
        jsonGenerator.writeObjectField(GraphSONTokens.KEY, entry.getKey()); 
        jsonGenerator.writeObjectField(GraphSONTokens.VALUE, entry.getValue());
        jsonGenerator.writeEndObject();
    }
    jsonGenerator.writeEndObject();
}
 
Example 3
Source File: TraversalSerializersV3d0.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(final P p, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
        throws IOException {
    jsonGenerator.writeStartObject();
    jsonGenerator.writeStringField(GraphSONTokens.PREDICATE,
            p instanceof ConnectiveP ?
                    p instanceof AndP ?
                            GraphSONTokens.AND :
                            GraphSONTokens.OR :
                    p.getBiPredicate().toString());
    if (p instanceof ConnectiveP) {
        jsonGenerator.writeArrayFieldStart(GraphSONTokens.VALUE);
        for (final P<?> predicate : ((ConnectiveP<?>) p).getPredicates()) {
            jsonGenerator.writeObject(predicate);
        }
        jsonGenerator.writeEndArray();
    } else
        jsonGenerator.writeObjectField(GraphSONTokens.VALUE, p.getValue());

    jsonGenerator.writeEndObject();
}
 
Example 4
Source File: HugeGraphSONModule.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(HugeVertex vertex, JsonGenerator generator,
                      SerializerProvider provider)
                      throws IOException {
    vertex.forceLoad();
    generator.writeStartObject();

    this.writeIdField("id", vertex.id(), generator);
    generator.writeStringField("label", vertex.label());
    generator.writeStringField("type", "vertex");

    this.writePropertiesField(vertex.getFilledProperties(),
                              generator, provider);

    generator.writeEndObject();
}
 
Example 5
Source File: AbstractGraphSONMessageSerializerV2d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
public void ser(final RequestMessage requestMessage, final JsonGenerator jsonGenerator,
                final SerializerProvider serializerProvider,
                final TypeSerializer typeSerializer) throws IOException {
    GraphSONUtil.writeStartObject(requestMessage, jsonGenerator, typeSerializer);

    jsonGenerator.writeStringField(SerTokens.TOKEN_REQUEST, requestMessage.getRequestId().toString());
    jsonGenerator.writeStringField(SerTokens.TOKEN_OP, requestMessage.getOp());
    jsonGenerator.writeStringField(SerTokens.TOKEN_PROCESSOR, requestMessage.getProcessor());
    jsonGenerator.writeObjectField(SerTokens.TOKEN_ARGS, requestMessage.getArgs());

    GraphSONUtil.writeEndObject(requestMessage, jsonGenerator, typeSerializer);
}
 
Example 6
Source File: GraphSONSerializersV1d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
private static void ser(final Property property, final JsonGenerator jsonGenerator,
                        final SerializerProvider serializerProvider, final TypeSerializer typeSerializer) throws IOException {
    jsonGenerator.writeStartObject();
    if (typeSerializer != null) jsonGenerator.writeStringField(GraphSONTokens.CLASS, HashMap.class.getName());
    serializerProvider.defaultSerializeField(GraphSONTokens.KEY, property.key(), jsonGenerator);
    serializerProvider.defaultSerializeField(GraphSONTokens.VALUE, property.value(), jsonGenerator);
    jsonGenerator.writeEndObject();
}
 
Example 7
Source File: CustomId.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void serializeWithType(final CustomId customId, final JsonGenerator jsonGenerator,
                              final SerializerProvider serializerProvider, final TypeSerializer typeSerializer) throws IOException, JsonProcessingException {
    // when the type is included add "class" as a key and then try to utilize as much of the
    // default serialization provided by jackson data-bind as possible.  for example, write
    // the uuid as an object so that when jackson serializes it, it uses the uuid serializer
    // to write it out with the type.  in this way, data-bind should be able to deserialize
    // it back when types are embedded.
    jsonGenerator.writeStartObject();
    jsonGenerator.writeStringField(GraphSONTokens.CLASS, CustomId.class.getName());
    jsonGenerator.writeStringField("cluster", customId.getCluster());
    jsonGenerator.writeObjectField("elementId", customId.getElementId());
    jsonGenerator.writeEndObject();
}
 
Example 8
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 9
Source File: TraversalSerializersV2d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(final P p, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
        throws IOException {
    jsonGenerator.writeStartObject();
    jsonGenerator.writeStringField(GraphSONTokens.PREDICATE,
            p instanceof ConnectiveP ?
                    p instanceof AndP ?
                            GraphSONTokens.AND :
                            GraphSONTokens.OR :
                    p.getBiPredicate().toString());
    if (p instanceof ConnectiveP) {
        jsonGenerator.writeArrayFieldStart(GraphSONTokens.VALUE);
        for (final P<?> predicate : ((ConnectiveP<?>) p).getPredicates()) {
            jsonGenerator.writeObject(predicate);
        }
        jsonGenerator.writeEndArray();
    } else {
        if (p.getValue() instanceof Collection) {
            jsonGenerator.writeArrayFieldStart(GraphSONTokens.VALUE);
            for (final Object object : (Collection) p.getValue()) {
                jsonGenerator.writeObject(object);
            }
            jsonGenerator.writeEndArray();
        } else
            jsonGenerator.writeObjectField(GraphSONTokens.VALUE, p.getValue());
    }
    jsonGenerator.writeEndObject();
}
 
Example 10
Source File: GraphSONSerializersV2d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(final Vertex vertex, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
        throws IOException {
    jsonGenerator.writeStartObject();

    jsonGenerator.writeObjectField(GraphSONTokens.ID, vertex.id());
    jsonGenerator.writeStringField(GraphSONTokens.LABEL, vertex.label());
    writeProperties(vertex, jsonGenerator);

    jsonGenerator.writeEndObject();

}
 
Example 11
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 12
Source File: JavaUtilSerializersV1d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
private static void ser(final Map.Entry entry, final JsonGenerator jsonGenerator,
                        final SerializerProvider serializerProvider, final TypeSerializer typeSerializer) throws IOException {
    jsonGenerator.writeStartObject();
    if (typeSerializer != null) jsonGenerator.writeStringField(GraphSONTokens.CLASS, HashMap.class.getName());

    // this treatment of keys is consistent with the current GraphSONKeySerializer which extends the
    // StdKeySerializer
    final Object key = entry.getKey();
    final Class cls = key.getClass();
    String k;
    if (cls == String.class)
        k = (String) key;
    else if (Element.class.isAssignableFrom(cls))
        k = ((Element) key).id().toString();
    else if(Date.class.isAssignableFrom(cls)) {
        if (serializerProvider.isEnabled(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS))
            k = String.valueOf(((Date) key).getTime());
        else
            k = serializerProvider.getConfig().getDateFormat().format((Date) key);
    } else if(cls == Class.class)
        k = ((Class) key).getName();
    else
        k = key.toString();

    serializerProvider.defaultSerializeField(k, entry.getValue(), jsonGenerator);
    jsonGenerator.writeEndObject();
}
 
Example 13
Source File: GraphSONSerializersV1d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
private void writeProperties(final Edge edge, final JsonGenerator jsonGenerator,
                                    final SerializerProvider serializerProvider,
                                    final TypeSerializer typeSerializer) throws IOException {
    final Iterator<Property<Object>> elementProperties = normalize ?
            IteratorUtils.list(edge.properties(), Comparators.PROPERTY_COMPARATOR).iterator() : edge.properties();
    if (elementProperties.hasNext()) {
        jsonGenerator.writeObjectFieldStart(GraphSONTokens.PROPERTIES);
        if (typeSerializer != null) jsonGenerator.writeStringField(GraphSONTokens.CLASS, HashMap.class.getName());
        while (elementProperties.hasNext()) {
            final Property<Object> elementProperty = elementProperties.next();
            GraphSONUtil.writeWithType(elementProperty.key(), elementProperty.value(), jsonGenerator, serializerProvider, typeSerializer);
        }
        jsonGenerator.writeEndObject();
    }
}
 
Example 14
Source File: TraversalSerializersV3d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(final Bytecode.Binding binding, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
        throws IOException {
    jsonGenerator.writeStartObject();
    jsonGenerator.writeStringField(GraphSONTokens.KEY, binding.variable());
    jsonGenerator.writeObjectField(GraphSONTokens.VALUE, binding.value());
    jsonGenerator.writeEndObject();
}
 
Example 15
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 16
Source File: GraphSONSerializersV1d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
private static void writeMetaProperties(final VertexProperty property, final JsonGenerator jsonGenerator,
                                        final SerializerProvider serializerProvider,
                                        final TypeSerializer typeSerializer, final boolean normalize) throws IOException {
    jsonGenerator.writeObjectFieldStart(GraphSONTokens.PROPERTIES);
    if (typeSerializer != null) jsonGenerator.writeStringField(GraphSONTokens.CLASS, HashMap.class.getName());
    final Iterator<Property<Object>> metaProperties = normalize ?
            IteratorUtils.list(( Iterator<Property<Object>>) property.properties(), Comparators.PROPERTY_COMPARATOR).iterator() : property.properties();
    while (metaProperties.hasNext()) {
        final Property<Object> metaProperty = metaProperties.next();
        GraphSONUtil.writeWithType(metaProperty.key(), metaProperty.value(), jsonGenerator, serializerProvider, typeSerializer);
    }
    jsonGenerator.writeEndObject();
}
 
Example 17
Source File: SchemaTable.java    From sqlg with MIT License 5 votes vote down vote up
@Override
public void serializeWithType(final SchemaTable schemaTable, final JsonGenerator jsonGenerator,
                              final SerializerProvider serializerProvider, final TypeSerializer typeSerializer) throws IOException {
    // when the type is included add "class" as a key and then try to utilize as much of the
    // default serialization provided by jackson data-bind as possible.  for example, write
    // the uuid as an object so that when jackson serializes it, it uses the uuid serializer
    // to write it out with the type.  in this way, data-bind should be able to deserialize
    // it back when types are embedded.
    jsonGenerator.writeStartObject();
    jsonGenerator.writeStringField(GraphSONTokens.CLASS, SchemaTable.class.getName());
    jsonGenerator.writeStringField("schema", schemaTable.getSchema());
    jsonGenerator.writeStringField("table", schemaTable.getTable());
    jsonGenerator.writeEndObject();
}
 
Example 18
Source File: JavaTimeSerializersV1d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void serializeWithType(final T value, final JsonGenerator gen,
                              final SerializerProvider serializers, final TypeSerializer typeSer) throws IOException {
    typeSer.writeTypePrefixForObject(value, gen);
    gen.writeStringField(GraphSONTokens.VALUE, value.toString());
    typeSer.writeTypeSuffixForObject(value, gen);
}
 
Example 19
Source File: AbstractGraphSONTypeSerializer.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
protected void writeTypePrefix(final JsonGenerator jsonGenerator, final String s) throws IOException {
    jsonGenerator.writeStartObject();
    jsonGenerator.writeStringField(propertyName, s);
    jsonGenerator.writeFieldName(this.valuePropertyName);
}
 
Example 20
Source File: MetricsModule.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(Timer timer, JsonGenerator json,
                      SerializerProvider provider) throws IOException {
    json.writeStartObject();
    final Snapshot snapshot = timer.getSnapshot();
    json.writeNumberField("count", timer.getCount());
    json.writeNumberField("max", snapshot.getMax() *
                                 this.durationFactor);
    json.writeNumberField("mean", snapshot.getMean() *
                                  this.durationFactor);
    json.writeNumberField("min", snapshot.getMin() *
                                 this.durationFactor);

    json.writeNumberField("p50", snapshot.getMedian() *
                                 this.durationFactor);
    json.writeNumberField("p75", snapshot.get75thPercentile() *
                                 this.durationFactor);
    json.writeNumberField("p95", snapshot.get95thPercentile() *
                                 this.durationFactor);
    json.writeNumberField("p98", snapshot.get98thPercentile() *
                                 this.durationFactor);
    json.writeNumberField("p99", snapshot.get99thPercentile() *
                                 this.durationFactor);
    json.writeNumberField("p999", snapshot.get999thPercentile() *
                                  this.durationFactor);

    if (this.showSamples) {
        final long[] values = snapshot.getValues();
        final double[] scaledValues = new double[values.length];
        for (int i = 0; i < values.length; i++) {
            scaledValues[i] = values[i] * this.durationFactor;
        }
        json.writeObjectField("values", scaledValues);
    }

    json.writeNumberField("stddev", snapshot.getStdDev() *
                                    this.durationFactor);
    json.writeNumberField("m15_rate", timer.getFifteenMinuteRate() *
                                      this.rateFactor);
    json.writeNumberField("m1_rate", timer.getOneMinuteRate() *
                                     this.rateFactor);
    json.writeNumberField("m5_rate", timer.getFiveMinuteRate() *
                                     this.rateFactor);
    json.writeNumberField("mean_rate", timer.getMeanRate() *
                                       this.rateFactor);
    json.writeStringField("duration_units", this.durationUnit);
    json.writeStringField("rate_units", this.rateUnit);
    json.writeEndObject();
}