Jpype java to python type conversions

61 Views Asked by At

Say I create a simple java type with jpype:

jt = jpype.java.lang.System.currentTimeMillis()
print(jt)
print(type(jt))

pt = int(jt)
print(pt)
print(type(pt))

This produces:

1693604984710
<java class 'JLong'>
1693604984710
<class 'int'>

as expected.

Now my problem here is that I have a class with a bunch of getters that I want to call and put results into a python dict. That part works fine, however I don't get ints, I get JLongs (and similar for other java classes) which causes issues downstream.

Is there something in jpype that allows standard java types (including boxed types such as Integer) to be converted to python types or do I have to do it manually?

0

There are 0 best solutions below