Skip to content

Commit

Permalink
Fix array selection on edge traversals in SQL from REST
Browse files Browse the repository at this point in the history
eg. SELECT out()[0..2]:{*} FROM …

Resolves: #8778
  • Loading branch information
luigidellaquila committed Mar 8, 2019
1 parent 6c0dc33 commit 4ae123d
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.orientechnologies.orient.core.record.impl.OBlob;
import com.orientechnologies.orient.core.util.ODateHelper;

import java.lang.reflect.Array;
import java.util.*;

/**
Expand Down Expand Up @@ -206,8 +207,18 @@ default String toJson(Object val) {
jsonVal = "\"" + Base64.getEncoder().encodeToString((byte[]) val) + "\"";
} else if (val instanceof Date) {
jsonVal = "\"" + ODateHelper.getDateTimeFormatInstance().format(val) + "\"";
} else if (val.getClass().isArray()) {
StringBuilder builder = new StringBuilder();
builder.append("[");
for (int i = 0; i < Array.getLength(val); i++) {
if (i > 0) {
builder.append(", ");
}
builder.append(toJson(Array.get(val, i)));
}
builder.append("]");
jsonVal = builder.toString();
} else {

throw new UnsupportedOperationException("Cannot convert " + val + " - " + val.getClass() + " to JSON");
}
return jsonVal;
Expand Down

0 comments on commit 4ae123d

Please sign in to comment.