Commit ce9e7d0f authored by Jess Sightler's avatar Jess Sightler
Browse files

Fixed a bug that caused exceptions in the case of a vertex property with a...

Fixed a bug that caused exceptions in the case of a vertex property with a cardinality other than single
parent 3fc3931a
......@@ -23,9 +23,12 @@
package com.syncleus.ferma;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.structure.*;
......@@ -232,6 +235,23 @@ public abstract class AbstractVertexFrame extends AbstractElementFrame implement
return this.setLinkBothExplicit(new DefaultClassInitializer<>(kind), labels);
private Object getPropertySupportingMultiproperty(final String name) {
final Iterator<VertexProperty<Object>> propertyIterator = getElement().properties(name);
List<Object> results = new ArrayList<>();
while (propertyIterator.hasNext()) {
Property<Object> property =;
if (property.isPresent()) {
if (results.size() == 1) {
return results.get(0);
} else {
return results;
public JsonObject toJson() {
final JsonObject json = new JsonObject();
......@@ -241,15 +261,27 @@ public abstract class AbstractVertexFrame extends AbstractElementFrame implement
json.addProperty("id", getId(String.class));
json.addProperty("elementClass", "vertex");
for (final String key : getPropertyKeys()) {
final Object value = getProperty(key);
Object value = getPropertySupportingMultiproperty(key);
if (value instanceof Number)
json.addProperty(key, (Number) value);
else if(value instanceof Boolean)
json.addProperty(key, (Boolean) value);
else if(value instanceof Character)
json.addProperty(key, (Character) value);
else if (value instanceof List) {
JsonArray jsonArray = new JsonArray();
((List) value).forEach(item -> {
if (item instanceof Number)
jsonArray.add((Number) item);
else if(item instanceof Boolean)
jsonArray.add((Boolean) item);
else if(item instanceof Character)
jsonArray.add((Character) item);
json.add(key, jsonArray);
} else
json.addProperty(key, value.toString());
return json;
......@@ -17,6 +17,8 @@ package com.syncleus.ferma;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
import org.junit.Assert;
import org.junit.Before;
......@@ -26,6 +28,8 @@ import;
import com.syncleus.ferma.graphtypes.javaclass.JavaAccessModifier;
import java.util.Iterator;
import org.apache.tinkerpop.gremlin.structure.T;
import org.junit.After;
......@@ -211,6 +215,31 @@ public class AbstractElementFrameTest {
Assert.assertEquals(expected.getProperty(charPropName), (Character) actual.get(charPropName).getAsCharacter());
public void testVtoJSonMultiproperty() {
String stringPropName = "custom-string-property";
String stringPropValue = "custom-string-value";
String charPropName = "custom-char-property";
Character charPropValue = 'D';
String intPropName = "custom-int-property";
int intPropValue = 1234;
Person expected = fg.addFramedVertex(Person.DEFAULT_INITIALIZER,, "some-id",
stringPropName, stringPropValue,
charPropName, charPropValue,
intPropName, intPropValue);
Vertex vertex = expected.getElement();
String key = "multiproperty";, key, "value1");, key, "value2");, key, "value3");, key, "value4");
JsonObject actual = expected.toJson();
public void testEtoJson() {
JsonObject actual = e1.toJson();
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment