I wonder if it possible to not have jython automagicaly transform java objects to python types when you put them in a Java ArrayList.
Example copied from a jython-console:
>>> b = java.lang.Boolean("True");
>>> type(b)
<type 'javainstance'>
>>> isinstance(b, java.lang.Boolean);
1
So far, everything is fine but if I put the object in an ArrayList
>>> l = java.util.ArrayList();
>>> l.add(b)
1
>>> type(l.get(0))
<type 'int'>
the object is transformed into a python-like boolean (i.e. an int) and...
>>> isinstance(l.get(0), java.lang.Boolean)
0
which means that I can no longer see that this was once a java.lang.Boolean.
Clarification
I guess what really want to achieve is to get rid of the implicit conversion from Java-types to Python-types when passing objects from Java to Python. I will give another example for clarification.
A Python module:
import java
import IPythonModule
class PythonModule(IPythonModule):
def method(self, data):
print type(data);
And a Java-Class that uses this module:
import java.util.ArrayList;
import org.python.core.PyList;
import org.testng.annotations.*;
import static org.testng.AssertJUnit.*;
public class Test1 {
IPythonModule m;
@BeforeClass
public void setUp() {
JythonFactory jf = JythonFactory.getInstance();
m = (IPythonModule) jf.getJythonObject(
"IPythonModule",
"/Users/sg/workspace/JythonTests/src/PythonModule.py");
}
@Test
public void testFirst() {
m.method(new Boolean("true"));
}
}
Here I will see the output 'bool' because of the implicit conversion, but what I would really like is to see 'javainstance' or 'java.lang.Boolean'. If you want to run this code you will also need the JythonFactory-class that can be found here.