From 20b4bd5d62941b2093e54946ad2b56272643bc23 Mon Sep 17 00:00:00 2001 From: Amirouche Boubekki Date: Mon, 1 Oct 2012 01:21:24 +0200 Subject: [PATCH] allow to use python list and tuple as Object params --- jnius/jnius_conversion.pxi | 2 ++ tests/org/jnius/BasicsTest.java | 4 ++++ tests/test_basics.py | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/jnius/jnius_conversion.pxi b/jnius/jnius_conversion.pxi index 1828153..74870e7 100644 --- a/jnius/jnius_conversion.pxi +++ b/jnius/jnius_conversion.pxi @@ -52,6 +52,8 @@ cdef void populate_args(JNIEnv *j_env, list definition_args, jvalue *j_args, arg elif isinstance(py_arg, JavaObject): jo = py_arg j_args[index].l = jo.obj + elif isinstance(py_arg, (tuple, list)): + j_args[index].l = convert_pyarray_to_java(j_env, argtype, py_arg) else: raise JavaException('Invalid python object for this ' 'argument. Want {0!r}, got {1!r}'.format( diff --git a/tests/org/jnius/BasicsTest.java b/tests/org/jnius/BasicsTest.java index 091e71c..066c61d 100644 --- a/tests/org/jnius/BasicsTest.java +++ b/tests/org/jnius/BasicsTest.java @@ -112,4 +112,8 @@ public class BasicsTest { return false; return (x[0].equals("hello") && x[1].equals("world")); } + + public boolean methodParamsObject(Object x) { + return true; + } } diff --git a/tests/test_basics.py b/tests/test_basics.py index fb81f60..e060ac2 100644 --- a/tests/test_basics.py +++ b/tests/test_basics.py @@ -77,3 +77,8 @@ class BasicsTest(unittest.TestCase): self.assertEquals(test.methodParamsArrayI([1, 2, 3]), True) self.assertEquals(test.methodParamsArrayString([ 'hello', 'world']), True) + + def test_instances_methods_params_object_list_str(self): + test = autoclass('org.jnius.BasicsTest')() + self.assertEquals(test.methodParamsObject([ + 'hello', 'world']), True)