org.apache.tinkerpop.shaded.jackson.databind.SerializerProvider Java Examples

The following examples show how to use org.apache.tinkerpop.shaded.jackson.databind.SerializerProvider. 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 Project: sqlg   Author: pietermartin   File: SchemaTable.java    License: MIT License 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public void serializeWithType(final SchemaTable schemaTable, 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.
    typeSerializer.writeTypePrefixForScalar(schemaTable, jsonGenerator);
    final Map<String, Object> m = new LinkedHashMap<>();
    m.put("schema", schemaTable.getSchema());
    m.put("table", schemaTable.getTable());
    jsonGenerator.writeObject(m);
    typeSerializer.writeTypeSuffixForScalar(schemaTable, jsonGenerator);
}
 
Example #2
Source Project: tinkerpop   Author: apache   File: JavaUtilSerializersV2d0.java    License: Apache License 2.0 6 votes vote down vote up
private static void ser(final Map.Entry entry, final JsonGenerator jsonGenerator,
                        final SerializerProvider serializerProvider) throws IOException {
    // 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);
}
 
Example #3
Source Project: hugegraph   Author: hugegraph   File: MetricsModule.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(Histogram histogram, JsonGenerator json,
                      SerializerProvider provider) throws IOException {
    json.writeStartObject();
    final Snapshot snapshot = histogram.getSnapshot();
    json.writeNumberField("count", histogram.getCount());
    json.writeNumberField("max", snapshot.getMax());
    json.writeNumberField("mean", snapshot.getMean());
    json.writeNumberField("min", snapshot.getMin());
    json.writeNumberField("p50", snapshot.getMedian());
    json.writeNumberField("p75", snapshot.get75thPercentile());
    json.writeNumberField("p95", snapshot.get95thPercentile());
    json.writeNumberField("p98", snapshot.get98thPercentile());
    json.writeNumberField("p99", snapshot.get99thPercentile());
    json.writeNumberField("p999", snapshot.get999thPercentile());

    if (this.showSamples) {
        json.writeObjectField("values", snapshot.getValues());
    }

    json.writeNumberField("stddev", snapshot.getStdDev());
    json.writeEndObject();
}
 
Example #4
Source Project: hugegraph   Author: hugegraph   File: MetricsModule.java    License: 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 #5
Source Project: sqlg   Author: pietermartin   File: RecordId.java    License: MIT License 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public void serializeWithType(final RecordId recordId, 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.
    typeSerializer.writeTypePrefixForScalar(recordId, jsonGenerator);
    final Map<String, Object> m = new LinkedHashMap<>();
    m.put("schemaTable", recordId.getSchemaTable());
    if (recordId.hasSequenceId()) {
        m.put("id", recordId.sequenceId());
    } else {
        m.put("id", recordId.getIdentifiers());
    }
    jsonGenerator.writeObject(m);
    typeSerializer.writeTypeSuffixForScalar(recordId, jsonGenerator);
}
 
Example #6
Source Project: tinkergraph-gremlin   Author: ShiftLeftSecurity   File: TinkerIoRegistryV2d0.java    License: 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 #7
Source Project: tinkerpop   Author: apache   File: AbstractGraphSONMessageSerializerV1d0.java    License: Apache License 2.0 6 votes vote down vote up
public void ser(final ResponseMessage responseMessage, final JsonGenerator jsonGenerator,
                final SerializerProvider serializerProvider,
                final TypeSerializer typeSerializer) throws IOException, JsonProcessingException {
    jsonGenerator.writeStartObject();
    if (typeSerializer != null) jsonGenerator.writeStringField(GraphSONTokens.CLASS, HashMap.class.getName());

    jsonGenerator.writeStringField(SerTokens.TOKEN_REQUEST, responseMessage.getRequestId() != null ? responseMessage.getRequestId().toString() : null);
    jsonGenerator.writeObjectFieldStart(SerTokens.TOKEN_STATUS);

    if (typeSerializer != null) jsonGenerator.writeStringField(GraphSONTokens.CLASS, HashMap.class.getName());
    jsonGenerator.writeStringField(SerTokens.TOKEN_MESSAGE, responseMessage.getStatus().getMessage());
    jsonGenerator.writeNumberField(SerTokens.TOKEN_CODE, responseMessage.getStatus().getCode().getValue());
    jsonGenerator.writeObjectField(SerTokens.TOKEN_ATTRIBUTES, responseMessage.getStatus().getAttributes());
    jsonGenerator.writeEndObject();

    jsonGenerator.writeObjectFieldStart(SerTokens.TOKEN_RESULT);
    if (typeSerializer != null) jsonGenerator.writeStringField(GraphSONTokens.CLASS, HashMap.class.getName());
    if (null == responseMessage.getResult().getData())
        jsonGenerator.writeNullField(SerTokens.TOKEN_DATA);
    else
        GraphSONUtil.writeWithType(SerTokens.TOKEN_DATA, responseMessage.getResult().getData(), jsonGenerator, serializerProvider, typeSerializer);
    jsonGenerator.writeObjectField(SerTokens.TOKEN_META, responseMessage.getResult().getMeta());
    jsonGenerator.writeEndObject();

    jsonGenerator.writeEndObject();
}
 
Example #8
Source Project: tinkerpop   Author: apache   File: GraphSONSerializersV1d0.java    License: Apache License 2.0 6 votes vote down vote up
private static void tryWriteMetaProperties(final VertexProperty property, final JsonGenerator jsonGenerator,
                                           final SerializerProvider serializerProvider,
                                           final TypeSerializer typeSerializer, final boolean normalize) throws IOException {
    // when "detached" you can't check features of the graph it detached from so it has to be
    // treated differently from a regular VertexProperty implementation.
    if (property instanceof DetachedVertexProperty) {
        // only write meta properties key if they exist
        if (property.properties().hasNext()) {
            writeMetaProperties(property, jsonGenerator, serializerProvider, typeSerializer, normalize);
        }
    } else {
        // still attached - so we can check the features to see if it's worth even trying to write the
        // meta properties key
        if (property.graph().features().vertex().supportsMetaProperties() && property.properties().hasNext()) {
            writeMetaProperties(property, jsonGenerator, serializerProvider, typeSerializer, normalize);
        }
    }
}
 
Example #9
Source Project: tinkerpop   Author: apache   File: GraphSONSerializersV3d0.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(final TraversalExplanation traversalExplanation, final JsonGenerator jsonGenerator,
                      final SerializerProvider serializerProvider) throws IOException {
    final Map<String, Object> m = new HashMap<>();
    m.put(GraphSONTokens.ORIGINAL, getStepsAsList(traversalExplanation.getOriginalTraversal()));

    final List<Pair<TraversalStrategy, Traversal.Admin<?, ?>>> strategyTraversals = traversalExplanation.getStrategyTraversals();

    final List<Map<String, Object>> intermediates = new ArrayList<>();
    for (final Pair<TraversalStrategy, Traversal.Admin<?, ?>> pair : strategyTraversals) {
        final Map<String, Object> intermediate = new HashMap<>();
        intermediate.put(GraphSONTokens.STRATEGY, pair.getValue0().toString());
        intermediate.put(GraphSONTokens.CATEGORY, pair.getValue0().getTraversalCategory().getSimpleName());
        intermediate.put(GraphSONTokens.TRAVERSAL, getStepsAsList(pair.getValue1()));
        intermediates.add(intermediate);
    }
    m.put(GraphSONTokens.INTERMEDIATE, intermediates);

    if (strategyTraversals.isEmpty())
        m.put(GraphSONTokens.FINAL, getStepsAsList(traversalExplanation.getOriginalTraversal()));
    else
        m.put(GraphSONTokens.FINAL, getStepsAsList(strategyTraversals.get(strategyTraversals.size() - 1).getValue1()));

    jsonGenerator.writeObject(m);
}
 
Example #10
Source Project: tinkerpop   Author: apache   File: GraphSONSerializersV3d0.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(final Metrics metrics, final JsonGenerator jsonGenerator,
                      final SerializerProvider serializerProvider) throws IOException {
    final Map<String, Object> m = new HashMap<>();
    m.put(GraphSONTokens.ID, metrics.getId());
    m.put(GraphSONTokens.NAME, metrics.getName());
    m.put(GraphSONTokens.COUNTS, metrics.getCounts());
    m.put(GraphSONTokens.DURATION, metrics.getDuration(TimeUnit.NANOSECONDS) / 1000000d);

    if (!metrics.getAnnotations().isEmpty()) {
        m.put(GraphSONTokens.ANNOTATIONS, metrics.getAnnotations());
    }
    if (!metrics.getNested().isEmpty()) {
        final List<Metrics> nested = new ArrayList<>();
        metrics.getNested().forEach(it -> nested.add(it));
        m.put(GraphSONTokens.METRICS, nested);
    }
    jsonGenerator.writeObject(m);
}
 
Example #11
Source Project: hugegraph   Author: hugegraph   File: RolePermission.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(RolePermission role, JsonGenerator generator,
                      SerializerProvider provider)
                      throws IOException {
    generator.writeStartObject();
    generator.writeObjectField("roles", role.map);
    generator.writeEndObject();
}
 
Example #12
Source Project: hugegraph   Author: hugegraph   File: HugeGraphSONModule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(Optional optional,
                      JsonGenerator jsonGenerator,
                      SerializerProvider provider)
                      throws IOException {
    if (optional.isPresent()) {
        jsonGenerator.writeObject(optional.get());
    } else {
        jsonGenerator.writeObject(null);
    }
}
 
Example #13
Source Project: hugegraph   Author: hugegraph   File: HugeGraphSONModule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(PropertyKey pk,
                      JsonGenerator jsonGenerator,
                      SerializerProvider provider)
                      throws IOException {
    writeEntry(jsonGenerator, schemaSerializer.writePropertyKey(pk));
}
 
Example #14
Source Project: hugegraph   Author: hugegraph   File: HugeGraphSONModule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(EdgeLabel el,
                      JsonGenerator jsonGenerator,
                      SerializerProvider provider)
                      throws IOException {
    writeEntry(jsonGenerator, schemaSerializer.writeEdgeLabel(el));
}
 
Example #15
Source Project: hugegraph   Author: hugegraph   File: HugeGraphSONModule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(IndexLabel il,
                      JsonGenerator jsonGenerator,
                      SerializerProvider provider)
                      throws IOException {
    writeEntry(jsonGenerator, schemaSerializer.writeIndexLabel(il));
}
 
Example #16
Source Project: tinkerpop   Author: apache   File: CustomId.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(final CustomId customId, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
        throws IOException, JsonGenerationException {
    // when types are not embedded, stringify or resort to JSON primitive representations of the
    // type so that non-jvm languages can better interoperate with the TinkerPop stack.
    jsonGenerator.writeString(customId.toString());
}
 
Example #17
Source Project: tinkerpop   Author: apache   File: GraphSONSerializersV1d0.java    License: 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 #18
Source Project: tinkerpop   Author: apache   File: GraphSONSerializersV1d0.java    License: Apache License 2.0 5 votes vote down vote up
private void ser(final Object o, final JsonGenerator jsonGenerator,
                 final SerializerProvider serializerProvider) throws IOException {
    if (Element.class.isAssignableFrom(o.getClass()))
        jsonGenerator.writeFieldName((((Element) o).id()).toString());
    else
        super.serialize(o, jsonGenerator, serializerProvider);
}
 
Example #19
Source Project: tinkerpop   Author: apache   File: GraphSONSerializersV2d0.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(final VertexProperty property, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
        throws IOException {
    jsonGenerator.writeStartObject();

    jsonGenerator.writeObjectField(GraphSONTokens.ID, property.id());
    jsonGenerator.writeObjectField(GraphSONTokens.VALUE, property.value());
    if (includeLabel)
        jsonGenerator.writeStringField(GraphSONTokens.LABEL, property.label());
    tryWriteMetaProperties(property, jsonGenerator, normalize);

    jsonGenerator.writeEndObject();
}
 
Example #20
Source Project: tinkerpop   Author: apache   File: TraversalSerializersV2d0.java    License: 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 #21
Source Project: hugegraph   Author: hugegraph   File: HugeGraphSONModule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(Shard shard, JsonGenerator jsonGenerator,
                      SerializerProvider provider)
                      throws IOException {
    jsonGenerator.writeStartObject();
    jsonGenerator.writeStringField("start", shard.start());
    jsonGenerator.writeStringField("end", shard.end());
    jsonGenerator.writeNumberField("length", shard.length());
    jsonGenerator.writeEndObject();
}
 
Example #22
Source Project: hugegraph   Author: hugegraph   File: HugeGraphSONModule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(File file, JsonGenerator jsonGenerator,
                      SerializerProvider provider)
                      throws IOException {
    jsonGenerator.writeStartObject();
    jsonGenerator.writeStringField("file", file.getName());
    jsonGenerator.writeEndObject();
}
 
Example #23
Source Project: hugegraph   Author: hugegraph   File: MetricsModule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(Gauge gauge, JsonGenerator json,
                      SerializerProvider provider) throws IOException {
    json.writeStartObject();
    final Object value;
    try {
        value = gauge.getValue();
        json.writeObjectField("value", value);
    } catch (RuntimeException e) {
        json.writeObjectField("error", e.toString());
    }
    json.writeEndObject();
}
 
Example #24
Source Project: hugegraph   Author: hugegraph   File: MetricsModule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(MetricRegistry registry, JsonGenerator json,
                      SerializerProvider provider) throws IOException {
    json.writeStartObject();
    json.writeStringField("version", VERSION.toString());
    json.writeObjectField("gauges", registry.getGauges(this.filter));
    json.writeObjectField("counters",
                          registry.getCounters(this.filter));
    json.writeObjectField("histograms",
                          registry.getHistograms(this.filter));
    json.writeObjectField("meters", registry.getMeters(this.filter));
    json.writeObjectField("timers", registry.getTimers(this.filter));
    json.writeEndObject();
}
 
Example #25
Source Project: tinkergraph-gremlin   Author: ShiftLeftSecurity   File: TinkerIoRegistryV1d0.java    License: 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 #26
Source Project: bitsy   Author: lambdazen   File: BitsyGraphSONModule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(final UUID uuid,
                      final JsonGenerator jsonGenerator,
                      final SerializerProvider serializerProvider)
        throws IOException, JsonGenerationException
{
    String uuidStr = UUID.toString(uuid);
    jsonGenerator.writeString(uuidStr);
}
 
Example #27
Source Project: tinkerpop   Author: apache   File: CustomId.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(final CustomId customId, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
        throws IOException, JsonGenerationException {
    final Map<String, Object> m = new HashMap<>();
    m.put("cluster", customId.getCluster());
    m.put("elementId", customId.getElementId());
    jsonGenerator.writeObject(m);
}
 
Example #28
Source Project: titan1withtp3.1   Author: graben1437   File: TitanGraphSONModule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void serializeWithType(final RelationIdentifier relationIdentifier, final JsonGenerator jsonGenerator,
                              final SerializerProvider serializerProvider, final TypeSerializer typeSerializer) throws IOException, JsonProcessingException {
    jsonGenerator.writeStartObject();
    jsonGenerator.writeStringField(GraphSONTokens.CLASS, RelationIdentifier.class.getName());
    jsonGenerator.writeStringField(FIELD_RELATION_ID, relationIdentifier.toString());
    jsonGenerator.writeEndObject();
}
 
Example #29
Source Project: sqlg   Author: pietermartin   File: RecordId.java    License: MIT License 5 votes vote down vote up
@Override
public void serialize(final RecordId recordId, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
        throws IOException {
    final Map<String, Object> m = new HashMap<>();
    m.put("schemaTable", recordId.getSchemaTable());
    if (recordId.hasSequenceId()) {
        m.put("id", recordId.sequenceId());
    } else {
        m.put("id", recordId.getIdentifiers());
    }
    jsonGenerator.writeObject(m);
}
 
Example #30
Source Project: tinkerpop   Author: apache   File: TraversalSerializersV2d0.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(final TraversalStrategy traversalStrategy, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
        throws IOException {
    jsonGenerator.writeStartObject();
    for (final Map.Entry<Object, Object> entry : ConfigurationConverter.getMap(traversalStrategy.getConfiguration()).entrySet()) {
        jsonGenerator.writeObjectField((String) entry.getKey(), entry.getValue());
    }
    jsonGenerator.writeEndObject();
}