AbstractGraphConverter implements GraphConverter { @Override public <T> Vertex toVertex(T entity) { requireNonNull(entity, "entity is required"); ClassMapping mapping = getClassMappings().get(entity.getClass()); String label = mapping.getName(); List<FieldGraph> fields = mapping.getFields().stream() .map(f -> to(f, entity)) .filter(FieldGraph::isNotEmpty).collect(toList()); Optional<FieldGraph> id = fields.stream().filter(FieldGraph::isId).findFirst(); final Function<Property, Vertex> findVertexOrCreateWithId = p -> { Iterator<Vertex> vertices = getGraph().vertices(p.value()); return vertices.hasNext() ? vertices.next() : getGraph().addVertex(org.apache.tinkerpop.gremlin.structure.T.label, label, org.apache.tinkerpop.gremlin.structure.T.id, p.value()); }; Vertex vertex = id.map(i -> i.toElement(getConverters())) .map(findVertexOrCreateWithId) .orElseGet(() -> getGraph().addVertex(label)); fields.stream().filter(FieldGraph::isNotId) .flatMap(f -> f.toElements(this, getConverters()).stream()) .forEach(p -> vertex.property(p.key(), p.value())); return vertex; }  @Override Vertex toVertex(T entity); @Override List<Property<?>> getProperties(T entity); @Override T toEntity(Vertex vertex); @Override T toEntity(Class<T> entityClass, Vertex vertex); @Override T toEntity(T entityInstance, Vertex vertex); @Override EdgeEntity toEdgeEntity(Edge edge); @Override Edge toEdge(EdgeEntity edge);  }
@Test public void shouldConvertEntityToTinkerPopVertexUsingNativeName() { Movie movie = new Movie("Matrix", 1999, null); Vertex vertex = getConverter().toVertex(movie); assertEquals("movie", vertex.label()); assertEquals(1999, Number.class.cast(vertex.value("movie_year")).intValue()); assertEquals("Matrix", vertex.value("title")); }