org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONWriter Java Examples
The following examples show how to use
org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONWriter.
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: GraphSONTranslator.java From tinkerpop with Apache License 2.0 | 6 votes |
public GraphSONTranslator(final JavaTranslator<S, T> wrappedTranslator, final GraphSONVersion version) { this.wrappedTranslator = wrappedTranslator; final GraphSONMapper mapper; if (version == GraphSONVersion.V2_0) { mapper = GraphSONMapper.build() .addCustomModule(GraphSONXModuleV2d0.build().create(false)).version(GraphSONVersion.V2_0).create(); } else if (version == GraphSONVersion.V3_0) { mapper = GraphSONMapper.build() .addCustomModule(GraphSONXModuleV3d0.build().create(false)).version(GraphSONVersion.V3_0).create(); } else { throw new IllegalArgumentException("GraphSONVersion." + version.name() + " is not supported for testing"); } writer = GraphSONWriter.build().mapper(mapper).create(); reader = GraphSONReader.build().mapper(mapper).create(); }
Example #2
Source File: IoTest.java From tinkerpop with Apache License 2.0 | 6 votes |
/** * Only need to execute this test with TinkerGraph or other graphs that support user supplied identifiers. */ @Test @FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_STRING_VALUES) @FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_INTEGER_VALUES) @FeatureRequirement(featureClass = EdgePropertyFeatures.class, feature = EdgePropertyFeatures.FEATURE_FLOAT_VALUES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_USER_SUPPLIED_IDS) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_NUMERIC_IDS) @FeatureRequirement(featureClass = Graph.Features.VertexPropertyFeatures.class, feature = Graph.Features.VertexPropertyFeatures.FEATURE_USER_SUPPLIED_IDS) @FeatureRequirement(featureClass = Graph.Features.VariableFeatures.class, feature = FEATURE_VARIABLES) @LoadGraphWith(LoadGraphWith.GraphData.CLASSIC) public void shouldWriteNormalizedGraphSON() throws Exception { try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { final GraphSONMapper mapper = graph.io(graphson).mapper().version(GraphSONVersion.V3_0).normalize(true).create(); final GraphSONWriter w = graph.io(graphson).writer().mapper(mapper).create(); w.writeGraph(bos, graph); final String expected = streamToString(getResourceAsStream(GraphSONResourceAccess.class, "tinkerpop-classic-normalized-v3d0.json")); assertEquals(expected.replace("\n", "").replace("\r", ""), bos.toString().replace("\n", "").replace("\r", "")); } }
Example #3
Source File: IoTest.java From tinkerpop with Apache License 2.0 | 6 votes |
/** * Only need to execute this test with TinkerGraph or other graphs that support user supplied identifiers. */ @Test @FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_STRING_VALUES) @FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_INTEGER_VALUES) @FeatureRequirement(featureClass = EdgePropertyFeatures.class, feature = EdgePropertyFeatures.FEATURE_FLOAT_VALUES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_USER_SUPPLIED_IDS) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_NUMERIC_IDS) @FeatureRequirement(featureClass = Graph.Features.VertexPropertyFeatures.class, feature = Graph.Features.VertexPropertyFeatures.FEATURE_USER_SUPPLIED_IDS) @FeatureRequirement(featureClass = Graph.Features.VariableFeatures.class, feature = FEATURE_VARIABLES) @LoadGraphWith(LoadGraphWith.GraphData.CLASSIC) public void shouldWriteNormalizedGraphSON() throws Exception { try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { final GraphSONMapper mapper = graph.io(graphson).mapper().version(GraphSONVersion.V2_0).typeInfo(TypeInfo.NO_TYPES).normalize(true).create(); final GraphSONWriter w = graph.io(graphson).writer().mapper(mapper).create(); w.writeGraph(bos, graph); final String expected = streamToString(getResourceAsStream(GraphSONResourceAccess.class, "tinkerpop-classic-normalized-v2d0.json")); assertEquals(expected.replace("\n", "").replace("\r", ""), bos.toString().replace("\n", "").replace("\r", "")); } }
Example #4
Source File: IoTest.java From tinkerpop with Apache License 2.0 | 6 votes |
/** * Only need to execute this test with TinkerGraph or other graphs that support user supplied identifiers. */ @Test @FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_STRING_VALUES) @FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_INTEGER_VALUES) @FeatureRequirement(featureClass = EdgePropertyFeatures.class, feature = EdgePropertyFeatures.FEATURE_FLOAT_VALUES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_USER_SUPPLIED_IDS) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_NUMERIC_IDS) @FeatureRequirement(featureClass = Graph.Features.VertexPropertyFeatures.class, feature = Graph.Features.VertexPropertyFeatures.FEATURE_USER_SUPPLIED_IDS) @FeatureRequirement(featureClass = Graph.Features.VariableFeatures.class, feature = FEATURE_VARIABLES) @LoadGraphWith(LoadGraphWith.GraphData.CLASSIC) public void shouldWriteNormalizedGraphSON() throws Exception { try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { final GraphSONMapper mapper = graph.io(graphson).mapper().version(GraphSONVersion.V1_0).normalize(true).create(); final GraphSONWriter w = graph.io(graphson).writer().mapper(mapper).create(); w.writeGraph(bos, graph); final String expected = streamToString(getResourceAsStream(GraphSONResourceAccess.class, "tinkerpop-classic-normalized-v1d0.json")); assertEquals(expected.replace("\n", "").replace("\r", ""), bos.toString().replace("\n", "").replace("\r", "")); } }
Example #5
Source File: GraphSONTranslator.java From tinkergraph-gremlin with Apache License 2.0 | 6 votes |
public GraphSONTranslator(final JavaTranslator<S, T> wrappedTranslator, final GraphSONVersion version) { this.wrappedTranslator = wrappedTranslator; final GraphSONMapper mapper; if (version == GraphSONVersion.V2_0) { mapper = GraphSONMapper.build() .addCustomModule(GraphSONXModuleV2d0.build().create(false)).version(GraphSONVersion.V2_0).create(); } else if (version == GraphSONVersion.V3_0) { mapper = GraphSONMapper.build() .addCustomModule(GraphSONXModuleV3d0.build().create(false)).version(GraphSONVersion.V3_0).create(); } else { throw new IllegalArgumentException("GraphSONVersion." + version.name() + " is not supported for testing"); } writer = GraphSONWriter.build().mapper(mapper).create(); reader = GraphSONReader.build().mapper(mapper).create(); }
Example #6
Source File: GraphSONMessageSerializerV2d0Test.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test public void shouldToStringUnknownObjects() { GraphSONMapper gm20 = GraphSONMapper.build().version(GraphSONVersion.V2_0).create(); GraphSONMapper gm10 = GraphSONMapper.build().version(GraphSONVersion.V1_0).create(); GraphWriter writer = GraphSONWriter.build().mapper(gm20).create(); // subsequent creations of GraphWriters and GraphSONMappers should not affect // each other. GraphWriter writer2 = GraphSONWriter.build().mapper(gm10).create(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { writer.writeObject(baos, new FunObject("value")); assertEquals(baos.toString(), "\"value\""); } catch (Exception e) { fail("should have succeeded serializing the unknown object to a string"); } }
Example #7
Source File: IoDataGenerationTest.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * No assertions. Just write out the graph for convenience. */ @Test public void shouldWriteClassicGraphAsGraphSONV2d0NoTypes() throws IOException { final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-classic-v2d0.json")); GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V2_0).typeInfo(TypeInfo.NO_TYPES).create()).create() .writeGraph(os, TinkerFactory.createClassic()); os.close(); }
Example #8
Source File: IoDataGenerationTest.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * No assertions. Just write out the graph for convenience. */ @Test public void shouldWriteSinkGraphAsGraphSONV3d0() throws IOException { final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-sink-v3d0.json")); GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V3_0).create()).create() .writeGraph(os, TinkerFactory.createKitchenSink()); os.close(); }
Example #9
Source File: IoDataGenerationTest.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * No assertions. Just write out the graph for convenience. */ @Test public void shouldWriteModernGraphAsGraphSOV2d0NNoTypes() throws IOException { final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-modern-v2d0.json")); GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V2_0).typeInfo(TypeInfo.NO_TYPES).create()).create() .writeGraph(os, TinkerFactory.createModern()); os.close(); }
Example #10
Source File: IoDataGenerationTest.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * No assertions. Just write out the graph for convenience. */ @Test public void shouldWriteCrewGraphAsGraphSONV2d0NoTypes() throws IOException { final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-crew-v2d0.json")); GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V2_0).typeInfo(TypeInfo.NO_TYPES).create()).create() .writeGraph(os, TinkerFactory.createTheCrew()); os.close(); }
Example #11
Source File: IoDataGenerationTest.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * No assertions. Just write out the graph for convenience */ @Test public void shouldWriteKitchenSinkAsGraphSONV2d0NoTypes() throws IOException { final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-sink-v2d0.json")); GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V2_0).typeInfo(TypeInfo.NO_TYPES).create()).create() .writeGraph(os, TinkerFactory.createKitchenSink()); os.close(); }
Example #12
Source File: IoDataGenerationTest.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * No assertions. Just write out the graph for convenience. */ @Test public void shouldWriteClassicGraphNormalizedAsGraphSONV2d0() throws IOException { final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-classic-normalized-v2d0.json")); GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V2_0).typeInfo(TypeInfo.NO_TYPES).normalize(true).create()).create() .writeGraph(os, TinkerFactory.createClassic()); os.close(); }
Example #13
Source File: IoDataGenerationTest.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * No assertions. Just write out the graph for convenience. */ @Test public void shouldWriteDEFAULTSinkGraphAsGraphSONV3d0() throws IOException { final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-sink.json")); GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V3_0).create()).create() .writeGraph(os, TinkerFactory.createKitchenSink()); os.close(); }
Example #14
Source File: IoDataGenerationTest.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * No assertions. Just write out the graph for convenience. */ @Test public void shouldWriteDEFAULTClassicGraphAsGraphSONV3d0() throws IOException { final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-classic.json")); GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V3_0).create()).create() .writeGraph(os, TinkerFactory.createClassic()); os.close(); }
Example #15
Source File: IoDataGenerationTest.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * No assertions. Just write out the graph for convenience. */ @Test public void shouldWriteDEFAULTModernGraphAsGraphSONV3d0() throws IOException { final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-modern.json")); GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V3_0).create()).create() .writeGraph(os, TinkerFactory.createModern()); os.close(); }
Example #16
Source File: IoDataGenerationTest.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * No assertions. Just write out the graph for convenience. */ @Test public void shouldWriteDEFAULTCrewGraphAsGraphSONV3d0() throws IOException { final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-crew.json")); GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V3_0).create()).create() .writeGraph(os, TinkerFactory.createTheCrew()); os.close(); }
Example #17
Source File: IoDataGenerationTest.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * No assertions. Just write out the graph for convenience. */ @Test public void shouldWriteModernGraphNormalizedAsGraphSONV3d0() throws IOException { final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-modern-normalized-v3d0.json")); GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V3_0).normalize(true).create()).create() .writeGraph(os, TinkerFactory.createModern()); os.close(); }
Example #18
Source File: AtlasJanusGraph.java From atlas with Apache License 2.0 | 5 votes |
@Override public void exportToGson(OutputStream os) throws IOException { GraphSONMapper mapper = getGraph().io(IoCore.graphson()).mapper().create(); GraphSONWriter.Builder builder = GraphSONWriter.build(); builder.mapper(mapper); GraphSONWriter writer = builder.create(); writer.writeGraph(os, getGraph()); }
Example #19
Source File: IoDataGenerationTest.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * No assertions. Just write out the graph for convenience */ @Test public void shouldWriteKitchenSinkAsGraphSONWithTypes() throws IOException { final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-sink-typed-v1d0.json")); GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V1_0).typeInfo(TypeInfo.PARTIAL_TYPES).create()) .create().writeGraph(os, TinkerFactory.createKitchenSink()); os.close(); }
Example #20
Source File: IoDataGenerationTest.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * No assertions. Just write out the graph for convenience. */ @Test public void shouldWriteCrewGraphAsGraphSONV1d0WithTypes() throws IOException { final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-crew-typed-v1d0.json")); GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V1_0).typeInfo(TypeInfo.PARTIAL_TYPES).create()) .create().writeGraph(os, TinkerFactory.createTheCrew()); os.close(); }
Example #21
Source File: IoDataGenerationTest.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * No assertions. Just write out the graph for convenience. */ @Test public void shouldWriteModernGraphAsGraphSONV1d0WithTypes() throws IOException { final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-modern-typed-v1d0.json")); GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V1_0).typeInfo(TypeInfo.PARTIAL_TYPES).create()) .create().writeGraph(os, TinkerFactory.createModern()); os.close(); }
Example #22
Source File: IoDataGenerationTest.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * No assertions. Just write out the graph for convenience. */ @Test public void shouldWriteClassicGraphAsGraphSONV1d0WithTypes() throws IOException { final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-classic-typed-v1d0.json")); GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V1_0).typeInfo(TypeInfo.PARTIAL_TYPES).create()) .create().writeGraph(os, TinkerFactory.createClassic()); os.close(); }
Example #23
Source File: IoDataGenerationTest.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * No assertions. Just write out the graph for convenience. */ @Test public void shouldWriteModernGraphNormalizedAsGraphSONV1d0() throws IOException { final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-modern-normalized-v1d0.json")); GraphSONWriter.build().mapper(GraphSONMapper.build().normalize(true).version(GraphSONVersion.V1_0).typeInfo(TypeInfo.NO_TYPES).create()).create().writeGraph(os, TinkerFactory.createModern()); os.close(); }
Example #24
Source File: IoDataGenerationTest.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * No assertions. Just write out the graph for convenience. */ @Test public void shouldWriteClassicGraphNormalizedAsGraphSONV1d0() throws IOException { final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-classic-normalized-v1d0.json")); GraphSONWriter.build().mapper(GraphSONMapper.build().normalize(true).version(GraphSONVersion.V1_0).typeInfo(TypeInfo.NO_TYPES).create()).create().writeGraph(os, TinkerFactory.createClassic()); os.close(); }
Example #25
Source File: IoDataGenerationTest.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * No assertions. Just write out the graph for convenience */ @Test public void shouldWriteKitchenSinkAsGraphSONNoTypes() throws IOException { final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-sink-v1d0.json")); GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V1_0).typeInfo(TypeInfo.NO_TYPES).create()).create().writeGraph(os, TinkerFactory.createKitchenSink()); os.close(); }
Example #26
Source File: IoDataGenerationTest.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * No assertions. Just write out the graph for convenience. */ @Test public void shouldWriteCrewGraphAsGraphSONV1d0NoTypes() throws IOException { final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-crew-v1d0.json")); GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V1_0).typeInfo(TypeInfo.NO_TYPES).create()).create().writeGraph(os, TinkerFactory.createTheCrew()); os.close(); }
Example #27
Source File: IoDataGenerationTest.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * No assertions. Just write out the graph for convenience. */ @Test public void shouldWriteModernGraphAsGraphSONV1d0NoTypes() throws IOException { final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-modern-v1d0.json")); GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V1_0).typeInfo(TypeInfo.NO_TYPES).create()).create().writeGraph(os, TinkerFactory.createModern()); os.close(); }
Example #28
Source File: IoDataGenerationTest.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * No assertions. Just write out the graph for convenience. */ @Test public void shouldWriteClassicGraphAsGraphSONV1d0NoTypes() throws IOException { final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-classic-v1d0.json")); GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V1_0).typeInfo(TypeInfo.NO_TYPES).create()).create().writeGraph(os, TinkerFactory.createClassic()); os.close(); }
Example #29
Source File: TinkerGraphTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test public void shouldSerializeTinkerGraphToGraphSONWithTypes() throws Exception { final TinkerGraph graph = TinkerFactory.createModern(); final Mapper<ObjectMapper> mapper = graph.io(IoCore.graphson()).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create(); try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) { final GraphWriter writer = GraphSONWriter.build().mapper(mapper).create(); writer.writeObject(out, graph); try (final ByteArrayInputStream inputStream = new ByteArrayInputStream(out.toByteArray())) { final GraphReader reader = GraphSONReader.build().mapper(mapper).create(); final TinkerGraph target = reader.readObject(inputStream, TinkerGraph.class); IoTest.assertModernGraph(target, true, false); } } }
Example #30
Source File: IoDataGenerationTest.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * No assertions. Just write out the graph for convenience. */ @Test public void shouldWriteModernGraphNormalizedAsGraphSONV2d0() throws IOException { final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-modern-normalized-v2d0.json")); GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V2_0).typeInfo(TypeInfo.NO_TYPES).normalize(true).create()).create() .writeGraph(os, TinkerFactory.createModern()); os.close(); }