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

The following examples show how to use org.apache.tinkerpop.shaded.jackson.core.JsonGenerator#writeObjectField() . 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: 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 2
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 3
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 4
Source File: TraversalSerializersV2d0.java    From tinkerpop with 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();
}
 
Example 5
Source File: TraversalSerializersV2d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(final Traverser traverserInstance, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
        throws IOException {
    jsonGenerator.writeStartObject();
    jsonGenerator.writeObjectField(GraphSONTokens.BULK, traverserInstance.bulk());
    jsonGenerator.writeObjectField(GraphSONTokens.VALUE, traverserInstance.get());
    jsonGenerator.writeEndObject();
}
 
Example 6
Source File: TraversalSerializersV2d0.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 7
Source File: TraversalSerializersV3d0.java    From tinkerpop with 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();
}
 
Example 8
Source File: GraphSONSerializersV2d0.java    From tinkerpop with 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 9
Source File: GraphSONSerializersV3d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(final Path path, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
        throws IOException, JsonGenerationException {
    jsonGenerator.writeStartObject();

    // paths shouldn't serialize with properties if the path contains graph elements
    final Path p = DetachedFactory.detach(path, false);
    jsonGenerator.writeObjectField(GraphSONTokens.LABELS, p.labels());
    jsonGenerator.writeObjectField(GraphSONTokens.OBJECTS, p.objects());

    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 Path path, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
        throws IOException, JsonGenerationException {
    jsonGenerator.writeStartObject();

    // paths shouldn't serialize with properties if the path contains graph elements
    final Path p = DetachedFactory.detach(path, false);
    jsonGenerator.writeObjectField(GraphSONTokens.LABELS, p.labels());
    jsonGenerator.writeObjectField(GraphSONTokens.OBJECTS, p.objects());

    jsonGenerator.writeEndObject();
}
 
Example 11
Source File: HugeResource.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(HugeResource res, JsonGenerator generator,
                      SerializerProvider provider)
                      throws IOException {
    generator.writeStartObject();

    generator.writeObjectField("type", res.type);
    generator.writeObjectField("label", res.label);
    generator.writeObjectField("properties", res.properties);

    generator.writeEndObject();
}
 
Example 12
Source File: GraphSONSerializersV2d0.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 boolean normalize) throws IOException {
    jsonGenerator.writeFieldName(GraphSONTokens.PROPERTIES);
    jsonGenerator.writeStartObject();

    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();
        jsonGenerator.writeObjectField(metaProperty.key(), metaProperty.value());
    }

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

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

    GraphSONUtil.writeStartObject(responseMessage, jsonGenerator, typeSerializer);
    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());
    GraphSONUtil.writeEndObject(responseMessage, jsonGenerator, typeSerializer);

    jsonGenerator.writeFieldName(SerTokens.TOKEN_RESULT);

    GraphSONUtil.writeStartObject(responseMessage, jsonGenerator, typeSerializer);

    if (null == responseMessage.getResult().getData()){
        jsonGenerator.writeNullField(SerTokens.TOKEN_DATA);
    } else {
        jsonGenerator.writeFieldName(SerTokens.TOKEN_DATA);
        final Object result = responseMessage.getResult().getData();
        serializerProvider.findTypedValueSerializer(result.getClass(), true, null).serialize(result, jsonGenerator, serializerProvider);
    }

    jsonGenerator.writeObjectField(SerTokens.TOKEN_META, responseMessage.getResult().getMeta());
    GraphSONUtil.writeEndObject(responseMessage, jsonGenerator, typeSerializer);

    GraphSONUtil.writeEndObject(responseMessage, jsonGenerator, typeSerializer);
}
 
Example 14
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 15
Source File: ToyTriangle.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(final ToyTriangle toyTriangle, final JsonGenerator jsonGenerator,
                      final SerializerProvider serializerProvider) throws IOException, JsonGenerationException {
    jsonGenerator.writeStartObject();
    jsonGenerator.writeObjectField("x", toyTriangle.x);
    jsonGenerator.writeObjectField("y", toyTriangle.y);
    jsonGenerator.writeObjectField("z", toyTriangle.z);
    jsonGenerator.writeEndObject();
}
 
Example 16
Source File: TraversalSerializersV3d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(final Traverser traverserInstance, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
        throws IOException {
    jsonGenerator.writeStartObject();
    jsonGenerator.writeObjectField(GraphSONTokens.BULK, traverserInstance.bulk());
    jsonGenerator.writeObjectField(GraphSONTokens.VALUE, traverserInstance.get());
    jsonGenerator.writeEndObject();
}
 
Example 17
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 18
Source File: GraphSONSerializersV1d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
private static void ser(final Path path, final JsonGenerator jsonGenerator, final TypeSerializer typeSerializer)
        throws IOException {
    jsonGenerator.writeStartObject();
    if (typeSerializer != null) jsonGenerator.writeStringField(GraphSONTokens.CLASS, HashMap.class.getName());
    jsonGenerator.writeObjectField(GraphSONTokens.LABELS, path.labels());
    jsonGenerator.writeObjectField(GraphSONTokens.OBJECTS, path.objects());
    jsonGenerator.writeEndObject();
}
 
Example 19
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 20
Source File: GraphSONSerializersV2d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(final Property property, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
        throws IOException {
    jsonGenerator.writeStartObject();
    jsonGenerator.writeObjectField(GraphSONTokens.KEY, property.key());
    jsonGenerator.writeObjectField(GraphSONTokens.VALUE, property.value());
    jsonGenerator.writeEndObject();
}