Skip to content

Commit

Permalink
Fix toJSON() for lists
Browse files Browse the repository at this point in the history
Resolves: #4107
  • Loading branch information
luigidellaquila committed Dec 2, 2015
1 parent 9ea2187 commit fdc4bd6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
Expand Up @@ -23,8 +23,6 @@
import com.orientechnologies.orient.core.record.impl.ODocument; import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.method.misc.OAbstractSQLMethod; import com.orientechnologies.orient.core.sql.method.misc.OAbstractSQLMethod;


import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;


/** /**
Expand Down Expand Up @@ -66,14 +64,14 @@ public Object execute(Object iThis, OIdentifiable iCurrentRecord, OCommandContex


} else if (OMultiValue.isMultiValue(iThis)) { } else if (OMultiValue.isMultiValue(iThis)) {


final List<String> result = new ArrayList<String>(); StringBuilder builder = new StringBuilder();
builder.append("[");
for (Object o : OMultiValue.getMultiValueIterable(iThis, false)) { for (Object o : OMultiValue.getMultiValueIterable(iThis, false)) {
if (o != null && o instanceof OIdentifiable) { builder.append(execute(o, iCurrentRecord, iContext, ioResult, iParams));
final ORecord record = ((OIdentifiable) o).getRecord();
result.add(iParams.length == 1 ? record.toJSON(format) : record.toJSON());
}
} }
return result;
builder.append("]");
return builder.toString();
} }
return null; return null;
} }
Expand Down
@@ -1,17 +1,16 @@
package com.orientechnologies.orient.core.sql; package com.orientechnologies.orient.core.sql;


import java.util.Collection; import com.orientechnologies.orient.core.command.script.OCommandScript;
import java.util.List; import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import java.util.Map; import com.orientechnologies.orient.core.record.impl.ODocument;

import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.AfterClass; import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;


import com.orientechnologies.orient.core.command.script.OCommandScript; import java.util.Collection;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; import java.util.List;
import com.orientechnologies.orient.core.record.impl.ODocument; import java.util.Map;


@Test @Test
public class OCommandExecutorSQLScriptTest { public class OCommandExecutorSQLScriptTest {
Expand Down Expand Up @@ -80,12 +79,15 @@ public void testReturnExpanded() throws Exception {
script = new StringBuilder(); script = new StringBuilder();
script.append("let $a = select from V limit 2\n"); script.append("let $a = select from V limit 2\n");
script.append("return $a.toJSON()\n"); script.append("return $a.toJSON()\n");
List<String> result = db.command(new OCommandScript("sql", script.toString())).execute(); String result = db.command(new OCommandScript("sql", script.toString())).execute();


Assert.assertNotNull(result); Assert.assertNotNull(result);
for (String d : result) { result = result.trim();
new ODocument().fromJSON(d); Assert.assertTrue(result.startsWith("["));
} Assert.assertTrue(result.endsWith("]"));

new ODocument().fromJSON(result.substring(1, result.length()-1));

} }


@Test @Test
Expand Down

0 comments on commit fdc4bd6

Please sign in to comment.