/** * {@inheritDoc} */ @Override public GraphSONMapper.Builder mapper() { final GraphSONMapper.Builder builder = GraphSONMapper.build().version(version); onMapper.ifPresent(c -> c.accept(builder)); return builder; }
@Test @LoadGraphWith(LoadGraphWith.GraphData.CREW) public void shouldSerializeVertexPropertyWithProperties() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().version(GraphSONVersion.V1_0).create().createMapper(); final VertexProperty vp = IteratorUtils.filter(graph.vertices(convertToVertexId("marko")).next().properties("location"), p -> p.value().equals("brussels")).next(); final String json = mapper.writeValueAsString(vp); final Map<String, Object> m = mapper.readValue(json, mapTypeReference); assertEquals(vp.label(), m.get(GraphSONTokens.LABEL)); assertNotNull(m.get(GraphSONTokens.ID)); assertEquals(vp.value(), m.get(GraphSONTokens.VALUE)); assertEquals(vp.values("startTime").next(), ((Map) m.get(GraphSONTokens.PROPERTIES)).get("startTime")); assertEquals(vp.values("endTime").next(), ((Map) m.get(GraphSONTokens.PROPERTIES)).get("endTime")); }
@Override public void initialize(final InputSplit genericSplit, final TaskAttemptContext context) throws IOException { this.lineRecordReader.initialize(genericSplit, context); this.hasEdges = context.getConfiguration().getBoolean(Constants.GREMLIN_HADOOP_GRAPH_READER_HAS_EDGES, true); this.graphsonReader = GraphSONReader.build().mapper( GraphSONMapper.build(). version(GraphSONVersion.valueOf(context.getConfiguration().get(Constants.GREMLIN_HADOOP_GRAPHSON_VERSION, "V3_0"))). typeInfo(TypeInfo.PARTIAL_TYPES). addRegistries(IoRegistryHelper.createRegistries(ConfUtil.makeApacheConfiguration(context.getConfiguration()))).create()).create(); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.CREW) public void shouldSerializeVertexPropertyWithProperties() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().version(GraphSONVersion.V3_0).create().createMapper(); final VertexProperty vp = IteratorUtils.filter(graph.vertices(convertToVertexId("marko")).next().properties("location"), p -> p.value().equals("brussels")).next(); final String json = mapper.writeValueAsString(vp); final VertexProperty<?> detached = mapper.readValue(json, VertexProperty.class); assertNotNull(detached); assertEquals(vp.label(), detached.label()); assertEquals(vp.id(), detached.id()); assertEquals(vp.value(), detached.value()); assertEquals(vp.values("startTime").next(), detached.values("startTime").next()); assertEquals(((Property) vp.properties("startTime").next()).key(), ((Property) detached.properties("startTime").next()).key()); assertEquals(vp.values("endTime").next(), detached.values("endTime").next()); assertEquals(((Property) vp.properties("endTime").next()).key(), ((Property) detached.properties("endTime").next()).key()); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeVertex() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().version(GraphSONVersion.V2_0).create().createMapper(); final Vertex v = graph.vertices(convertToVertexId("marko")).next(); final String json = mapper.writeValueAsString(v); final Vertex detached = mapper.readValue(json, Vertex.class); assertNotNull(detached); assertEquals(v.label(), detached.label()); assertEquals(v.id(), detached.id()); assertEquals(v.value("name").toString(), detached.value("name")); assertEquals((Integer) v.value("age"), detached.value("age")); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeVertex() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().version(GraphSONVersion.V3_0).create().createMapper(); final Vertex v = graph.vertices(convertToVertexId("marko")).next(); final String json = mapper.writeValueAsString(v); final Vertex detached = mapper.readValue(json, Vertex.class); assertNotNull(detached); assertEquals(v.label(), detached.label()); assertEquals(v.id(), detached.id()); assertEquals(v.value("name").toString(), detached.value("name")); assertEquals((Integer) v.value("age"), detached.value("age")); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeProperty() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().version(GraphSONVersion.V2_0).create().createMapper(); final Property p = g.E(convertToEdgeId("marko", "knows", "vadas")).next().property("weight"); final String json = mapper.writeValueAsString(p); final Property detached = mapper.readValue(json, Property.class); assertNotNull(detached); assertEquals(p.key(), detached.key()); assertEquals(p.value(), detached.value()); }
public GraphSONRecordWriter(final DataOutputStream outputStream, final Configuration configuration) { this.outputStream = outputStream; this.hasEdges = configuration.getBoolean(Constants.GREMLIN_HADOOP_GRAPH_WRITER_HAS_EDGES, true); this.graphsonWriter = GraphSONWriter.build().mapper( GraphSONMapper.build(). version(GraphSONVersion.valueOf(configuration.get(Constants.GREMLIN_HADOOP_GRAPHSON_VERSION, "V3_0"))). typeInfo(TypeInfo.PARTIAL_TYPES). addRegistries(IoRegistryHelper.createRegistries(ConfUtil.makeApacheConfiguration(configuration))).create()).create(); }
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); }
@Override GraphSONMapper.Builder configureBuilder(final GraphSONMapper.Builder builder) { // override the 2.0 in AbstractGraphSONMessageSerializerV2d0 return builder.version(GraphSONVersion.V3_0).addCustomModule(new GremlinServerModule()); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeVertexProperty() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().version(GraphSONVersion.V3_0).create().createMapper(); final VertexProperty vp = graph.vertices(convertToVertexId("marko")).next().property("name"); final String json = mapper.writeValueAsString(vp); final VertexProperty detached = mapper.readValue(json, VertexProperty.class); assertNotNull(detached); assertEquals(vp.label(), detached.label()); assertEquals(vp.id(), detached.id()); assertEquals(vp.value(), detached.value()); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeProperty() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().version(GraphSONVersion.V3_0).create().createMapper(); final Property p = g.E(convertToEdgeId("marko", "knows", "vadas")).next().property("weight"); final String json = mapper.writeValueAsString(p); final Property detached = mapper.readValue(json, Property.class); assertNotNull(detached); assertEquals(p.key(), detached.key()); assertEquals(p.value(), detached.value()); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeEdge() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().version(GraphSONVersion.V3_0).create().createMapper(); final Edge e = g.E(convertToEdgeId("marko", "knows", "vadas")).next(); final String json = mapper.writeValueAsString(e); final Edge detached = mapper.readValue(json, Edge.class); assertNotNull(detached); assertEquals(e.label(), detached.label()); assertEquals(e.id(), detached.id()); assertEquals((Double) e.value("weight"), detached.value("weight")); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeVertexProperty() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().version(GraphSONVersion.V1_0).create().createMapper(); final VertexProperty vp = graph.vertices(convertToVertexId("marko")).next().property("name"); final String json = mapper.writeValueAsString(vp); final Map<String, Object> m = mapper.readValue(json, mapTypeReference); assertEquals(vp.label(), m.get(GraphSONTokens.LABEL)); assertNotNull(m.get(GraphSONTokens.ID)); assertEquals(vp.value(), m.get(GraphSONTokens.VALUE)); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeProperty() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().version(GraphSONVersion.V1_0).create().createMapper(); final Property p = g.E(convertToEdgeId("marko", "knows", "vadas")).next().property("weight"); final String json = mapper.writeValueAsString(p); final Map<String, Object> m = mapper.readValue(json, mapTypeReference); assertEquals(p.value(), m.get(GraphSONTokens.VALUE)); assertEquals(p.key(), m.get(GraphSONTokens.KEY)); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeEdge() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().version(GraphSONVersion.V1_0).create().createMapper(); final Edge e = g.E(convertToEdgeId("marko", "knows", "vadas")).next(); final String json = mapper.writeValueAsString(e); final Map<String, Object> m = mapper.readValue(json, mapTypeReference); assertEquals(GraphSONTokens.EDGE, m.get(GraphSONTokens.TYPE)); assertEquals(e.label(), m.get(GraphSONTokens.LABEL)); assertNotNull(m.get(GraphSONTokens.ID)); assertEquals((Double) e.value("weight"), ((Map) m.get(GraphSONTokens.PROPERTIES)).get("weight")); }
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); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeVertexProperty() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().version(GraphSONVersion.V2_0).create().createMapper(); final VertexProperty vp = graph.vertices(convertToVertexId("marko")).next().property("name"); final String json = mapper.writeValueAsString(vp); final VertexProperty detached = mapper.readValue(json, VertexProperty.class); assertNotNull(detached); assertEquals(vp.label(), detached.label()); assertEquals(vp.id(), detached.id()); assertEquals(vp.value(), detached.value()); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeEdge() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().version(GraphSONVersion.V2_0).create().createMapper(); final Edge e = g.E(convertToEdgeId("marko", "knows", "vadas")).next(); final String json = mapper.writeValueAsString(e); final Edge detached = mapper.readValue(json, Edge.class); assertNotNull(detached); assertEquals(e.label(), detached.label()); assertEquals(e.id(), detached.id()); assertEquals((Double) e.value("weight"), detached.value("weight")); }
@Parameterized.Parameters(name = "{0}") public static Iterable<Object[]> data() { final GraphSONMapper v1mapper = GraphSONMapper.build().version(GraphSONVersion.V1_0).typeInfo(TypeInfo.PARTIAL_TYPES).addRegistry(JanusGraphIoRegistryV1d0.getInstance()).create(); final GraphSONMapper v2mapper = GraphSONMapper.build().version(GraphSONVersion.V2_0).typeInfo(TypeInfo.PARTIAL_TYPES).addRegistry(JanusGraphIoRegistry.getInstance()).create(); final GraphSONMapper v3mapper = GraphSONMapper.build().version(GraphSONVersion.V3_0).typeInfo(TypeInfo.PARTIAL_TYPES).addRegistry(JanusGraphIoRegistry.getInstance()).create(); return Arrays.asList(new Object[][]{ {"graphson-v1-embedded", (Function<Graph, GraphReader>) g -> GraphSONReader.build().mapper(v1mapper).create(), (Function<Graph, GraphWriter>) g -> GraphSONWriter.build().mapper(v1mapper).create()}, {"graphson-v2-embedded", (Function<Graph, GraphReader>) g -> GraphSONReader.build().mapper(v2mapper).create(), (Function<Graph, GraphWriter>) g -> GraphSONWriter.build().mapper(v2mapper).create()}, {"graphson-v3", (Function<Graph, GraphReader>) g -> GraphSONReader.build().mapper(v3mapper).create(), (Function<Graph, GraphWriter>) g -> GraphSONWriter.build().mapper(v3mapper).create()}, {"gryo", (Function<Graph, GraphReader>) g -> g.io(IoCore.gryo()).reader().mapper(g.io(IoCore.gryo()).mapper().create()).create(), (Function<Graph, GraphWriter>) g -> g.io(IoCore.gryo()).writer().mapper(g.io(IoCore.gryo()).mapper().create()).create()} }); }