diff --git a/hugegraph-core/pom.xml b/hugegraph-core/pom.xml
index c7a91e9c36..39aebc0c63 100644
--- a/hugegraph-core/pom.xml
+++ b/hugegraph-core/pom.xml
@@ -19,7 +19,7 @@
com.baidu.hugegraph
hugegraph-common
- 1.6.2
+ 1.6.3
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinarySerializer.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinarySerializer.java
index baadee43f4..37b6ac8fae 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinarySerializer.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinarySerializer.java
@@ -168,7 +168,7 @@ protected void parseProperty(Id pkeyId, byte[] val, HugeElement owner) {
PropertyKey pkey = owner.graph().propertyKey(pkeyId);
// Parse value
- Object value = KryoUtil.fromKryo(val, pkey.clazz());
+ Object value = KryoUtil.fromKryo(val, pkey.implementClazz());
// Set properties of vertex/edge
if (pkey.cardinality() == Cardinality.SINGLE) {
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TableSerializer.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TableSerializer.java
index 0115a91465..538de82792 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TableSerializer.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TableSerializer.java
@@ -96,7 +96,7 @@ protected void parseProperty(Id key, String colValue, HugeElement owner) {
PropertyKey pkey = owner.graph().propertyKey(key);
// Parse value
- Object value = JsonUtil.fromJson(colValue, pkey.clazz());
+ Object value = JsonUtil.fromJson(colValue, pkey.implementClazz());
// Set properties of vertex/edge
if (pkey.cardinality() == Cardinality.SINGLE) {
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TextSerializer.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TextSerializer.java
index 6ba192dcce..5fa34a8e1c 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TextSerializer.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TextSerializer.java
@@ -123,7 +123,7 @@ private void parseProperty(String colName, String colValue,
PropertyKey pkey = owner.graph().propertyKey(readId(colParts[1]));
// Parse value
- Object value = JsonUtil.fromJson(colValue, pkey.clazz());
+ Object value = JsonUtil.fromJson(colValue, pkey.implementClazz());
// Set properties of vertex/edge
if (pkey.cardinality() == Cardinality.SINGLE) {
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/PropertyKey.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/PropertyKey.java
index e0cbc41f65..47179aaecc 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/PropertyKey.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/PropertyKey.java
@@ -24,7 +24,6 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -84,7 +83,24 @@ public PropertyKey properties(Id... properties) {
return this;
}
- public Class> clazz() {
+ public String clazz() {
+ String dataType = this.dataType().clazz().getSimpleName();
+ switch (this.cardinality) {
+ case SINGLE:
+ return dataType;
+ // A set of values: Set
+ case SET:
+ return String.format("Set<%s>", dataType);
+ // A list of values: List
+ case LIST:
+ return String.format("List<%s>", dataType);
+ default:
+ throw new AssertionError(String.format(
+ "Unsupported cardinality: '%s'", this.cardinality));
+ }
+ }
+
+ public Class> implementClazz() {
Class> cls;
switch (this.cardinality) {
case SINGLE:
@@ -96,7 +112,7 @@ public Class> clazz() {
break;
// A list of values: List
case LIST:
- cls = LinkedList.class;
+ cls = ArrayList.class;
break;
default:
throw new AssertionError(String.format(
@@ -177,6 +193,16 @@ public Object serialValue(V value) {
return validValue;
}
+ public V validValueOrThrow(V value) {
+ V validValue = this.validValue(value);
+ E.checkArgument(validValue != null,
+ "Invalid property value '%s' for key '%s', " +
+ "expect a value of type %s, actual type %s",
+ value, this.name(), this.clazz(),
+ value.getClass().getSimpleName());
+ return validValue;
+ }
+
public V validValue(V value) {
return this.convValue(value, true);
}
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeElement.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeElement.java
index 9992b7ee90..dec6ac1b47 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeElement.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeElement.java
@@ -213,24 +213,14 @@ private HugeProperty addProperty(PropertyKey pkey, V value,
this.setProperty(property);
}
- Collection values = null;
- if (value instanceof Collection) {
- values = (Collection) value;
- } else if (value.getClass().isArray()) {
- values = CollectionUtil.toList(value);
- }
-
- if (values != null) {
- E.checkArgument(pkey.checkDataType(values),
- "Invalid type of property values %s for key '%s'",
- value, pkey.name());
- property.value().addAll(values);
+ Collection values;
+ if (pkey.cardinality() == Cardinality.SET) {
+ values = CollectionUtil.toSet(value);
} else {
- E.checkArgument(pkey.checkDataType(value),
- "Invalid type of property value '%s' for key '%s'",
- value, pkey.name());
- property.value().add(value);
+ assert pkey.cardinality() == Cardinality.LIST;
+ values = CollectionUtil.toList(value);
}
+ property.value().addAll(pkey.validValueOrThrow(values));
// Any better ways?
return (HugeProperty) property;
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeProperty.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeProperty.java
index cdaa484b99..7d6e2a427b 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeProperty.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeProperty.java
@@ -42,16 +42,7 @@ public HugeProperty(HugeElement owner, PropertyKey pkey, V value) {
this.owner = owner;
this.pkey = pkey;
- this.value = pkey.validValue(value);
-
- if (this.value == null) {
- E.checkArgument(false,
- "Invalid property value '%s' for key '%s', " +
- "expect a value of type %s, actual type %s",
- value, pkey.name(),
- pkey.clazz().getSimpleName(),
- value.getClass().getSimpleName());
- }
+ this.value = pkey.validValueOrThrow(value);
}
public PropertyKey propertyKey() {