Java Code Examples for org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper#Builder

The following examples show how to use org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper#Builder . 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: GraphSONMessageSerializerV2d0Test.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("deprecation")
public void shouldFailOnMessageSerializerWithMapperIfNoGremlinServerModule() {
    org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(AbstractGraphSONMessageSerializerV2d0.class);
    Level previousLevel = logger.getLevel();

    // Disable temporarily logging for this test
    logger.setLevel(Level.OFF);

    GraphSONMapper.Builder builder = GraphSONMapper.build().addCustomModule(GraphSONXModuleV2d0.build().create(false));
    GraphSONMessageSerializerV2d0 graphSONMessageSerializerV2d0 = new GraphSONMessageSerializerV2d0(builder.create());

    try {
        convert("hello", graphSONMessageSerializerV2d0);
        fail("Serialization should have failed since no GremlinServerModule registered.");
    } catch (SerializationException e) {
        assertTrue(e.getMessage().contains("Could not find a type identifier for the class"));
        assertTrue(e.getCause() instanceof JsonMappingException);
        assertTrue(e.getCause().getCause() instanceof IllegalArgumentException);
    }

    // Put logger level back to its original value
    logger.setLevel(previousLevel);
}
 
Example 2
Source File: GraphSONMessageSerializerV2d0Test.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRegisterGremlinServerModuleAutomaticallyWithMapper() throws SerializationException {
    GraphSONMapper.Builder builder = GraphSONMapper.build().addCustomModule(GraphSONXModuleV2d0.build().create(false));
    GraphSONMessageSerializerV2d0 graphSONMessageSerializerV2d0 = new GraphSONMessageSerializerV2d0(builder);

    ResponseMessage rm = convert("hello", graphSONMessageSerializerV2d0);
    assertEquals(rm.getRequestId(), requestId);
    assertEquals(rm.getResult().getData(), "hello");
}
 
Example 3
Source File: GraphSONMessageSerializerV3d0Test.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRegisterGremlinServerModuleAutomaticallyWithMapper() throws SerializationException {
    GraphSONMapper.Builder builder = GraphSONMapper.build().addCustomModule(GraphSONXModuleV3d0.build().create(false));
    GraphSONMessageSerializerV3d0 graphSONMessageSerializerV3d0 = new GraphSONMessageSerializerV3d0(builder);

    ResponseMessage rm = convert("hello", graphSONMessageSerializerV3d0);
    assertEquals(rm.getRequestId(), requestId);
    assertEquals(rm.getResult().getData(), "hello");
}
 
Example 4
Source File: BaseUtils.java    From atlas with Apache License 2.0 4 votes vote down vote up
private JsonNode getEntityNode(String json) throws IOException {
    GraphSONMapper.Builder builder = GraphSONMapper.build();
    final ObjectMapper mapper  = builder.typeInfo(TypeInfo.NO_TYPES).create().createMapper();
    return mapper.readTree(json);
}
 
Example 5
Source File: GraphSONMessageSerializerGremlinV1d0.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
GraphSONMapper.Builder configureBuilder(final GraphSONMapper.Builder builder) {
    // already set to 1.0 in AbstractGraphSONMessageSerializerV1d0
    return builder.addCustomModule(new GraphSONMessageSerializerV1d0.GremlinServerModule())
            .typeInfo(TypeInfo.PARTIAL_TYPES);
}
 
Example 6
Source File: AbstractGraphSONMessageSerializerV2d0.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
private GraphSONMapper.Builder initBuilder(final GraphSONMapper.Builder builder) {
    final GraphSONMapper.Builder b = null == builder ? GraphSONMapper.build() : builder;
    return b.addCustomModule(GraphSONXModuleV2d0.build().create(false))
            .version(GraphSONVersion.V2_0);
}
 
Example 7
Source File: AbstractGraphSONMessageSerializerV2d0.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public void configure(final Map<String, Object> config, final Map<String, Graph> graphs) {
    final GraphSONMapper.Builder initialBuilder = initBuilder(null);
    addIoRegistries(config, initialBuilder);
    mapper = configureBuilder(initialBuilder).create().createMapper();
}
 
Example 8
Source File: AbstractGraphSONMessageSerializerV2d0.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
public AbstractGraphSONMessageSerializerV2d0(final GraphSONMapper.Builder mapperBuilder) {
    this.mapper = configureBuilder(mapperBuilder).create().createMapper();
}
 
Example 9
Source File: AbstractGraphSONMessageSerializerV2d0.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
public AbstractGraphSONMessageSerializerV2d0() {
    final GraphSONMapper.Builder builder = configureBuilder(initBuilder(null));
    mapper = builder.create().createMapper();
}
 
Example 10
Source File: AbstractGraphSONMessageSerializerV1d0.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
private GraphSONMapper.Builder initBuilder(final GraphSONMapper.Builder builder) {
    final GraphSONMapper.Builder b = null == builder ? GraphSONMapper.build() : builder;
    return b.addCustomModule(new AbstractGraphSONMessageSerializerV1d0.GremlinServerModule())
            .version(GraphSONVersion.V1_0);
}
 
Example 11
Source File: AbstractGraphSONMessageSerializerV1d0.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public void configure(final Map<String, Object> config, final Map<String, Graph> graphs) {
    final GraphSONMapper.Builder initialBuilder = initBuilder(null);
    addIoRegistries(config, initialBuilder);
    mapper = configureBuilder(initialBuilder).create().createMapper();
}
 
Example 12
Source File: AbstractGraphSONMessageSerializerV1d0.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
public AbstractGraphSONMessageSerializerV1d0() {
    final GraphSONMapper.Builder builder = configureBuilder(initBuilder(null));
    mapper = builder.create().createMapper();
}
 
Example 13
Source File: GraphSONMessageSerializerGremlinV2d0.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
GraphSONMapper.Builder configureBuilder(final GraphSONMapper.Builder builder) {
    // already set to 2.0 in AbstractGraphSONMessageSerializerV2d0
    return builder.typeInfo(TypeInfo.PARTIAL_TYPES).addCustomModule(new GremlinServerModule());
}
 
Example 14
Source File: GraphSONMessageSerializerV1d0.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
GraphSONMapper.Builder configureBuilder(final GraphSONMapper.Builder builder) {
    // already set to 1.0 in AbstractGraphSONMessageSerializerV1d0
    return builder.addCustomModule(new GremlinServerModule())
            .typeInfo(TypeInfo.NO_TYPES);
}
 
Example 15
Source File: GraphSONMessageSerializerV3d0.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
GraphSONMapper.Builder configureBuilder(final GraphSONMapper.Builder builder) {
    // override the 2.0 in AbstractGraphSONMessageSerializerV2d0
    return builder.version(GraphSONVersion.V3_0).addCustomModule(new GremlinServerModule());
}
 
Example 16
Source File: GraphSONMessageSerializerV2d0.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
GraphSONMapper.Builder configureBuilder(final GraphSONMapper.Builder builder) {
    // already set to 2.0 in AbstractGraphSONMessageSerializerV2d0
    return builder.typeInfo(TypeInfo.PARTIAL_TYPES).addCustomModule(new GremlinServerModule());
}
 
Example 17
Source File: GraphSONMessageSerializerV3d0.java    From tinkerpop with Apache License 2.0 2 votes vote down vote up
/**
 * Create a GraphSONMessageSerializer with a provided {@link GraphSONMapper.Builder}.
 *
 * Note that to make this mapper usable in the context of request messages and responses,
 * this method will automatically register a {@link GremlinServerModule} to the provided
 * mapper.
 */
public GraphSONMessageSerializerV3d0(final GraphSONMapper.Builder mapperBuilder) {
    super(mapperBuilder);
}
 
Example 18
Source File: GraphSONMessageSerializerV2d0.java    From tinkerpop with Apache License 2.0 2 votes vote down vote up
/**
 * Create a GraphSONMessageSerializer with a provided {@link GraphSONMapper.Builder}.
 *
 * Note that to make this mapper usable in the context of request messages and responses,
 * this method will automatically register a {@link GremlinServerModule} to the provided
 * mapper.
 */
public GraphSONMessageSerializerV2d0(final GraphSONMapper.Builder mapperBuilder) {
    super(mapperBuilder);
}
 
Example 19
Source File: AbstractGraphSONMessageSerializerV1d0.java    From tinkerpop with Apache License 2.0 votes vote down vote up
abstract GraphSONMapper.Builder configureBuilder(final GraphSONMapper.Builder builder); 
Example 20
Source File: AbstractGraphSONMessageSerializerV2d0.java    From tinkerpop with Apache License 2.0 votes vote down vote up
abstract GraphSONMapper.Builder configureBuilder(final GraphSONMapper.Builder builder);