Title: __tojava__ does not support cast to user derived class
Type: Severity: major
Components: Core Versions: Jython 2.7
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: brianray, zyasoft
Priority: Keywords:

Created on 2014-07-24.14:53:55 by brianray, last changed 2015-04-28.16:07:32 by zyasoft.

msg8886 (view) Author: Brian ray (brianray) Date: 2014-07-24.14:53:54
I get the following exception:

>     Exception in thread "main" java.lang.ClassCastException:
>     org.python.core.PySingleton cannot be cast to 

This happens when I call 'return (ExampleApiJavaType) ExampleApiObject.__tojava__(ExampleApiJavaType.class)', full code here:

    import org.python.core.PyObject;
    import org.python.core.PyString;
    import org.python.util.PythonInterpreter;
    public class ExampleApiFactory {
        private PyObject ExampleApiClass;
        public ExampleApiFactory() {
            PythonInterpreter interpreter = new PythonInterpreter();
            interpreter.exec("from ExampleAPI import ExampleAPI");
            ExampleApiClass = interpreter.get("ExampleAPI");

        public ExampleApiJavaType create (String userid, String passw, String namespace, String URL, String api_level) {
            PyObject[] arguments = new PyObject[] {
                    new PyString(userid),
                    new PyString(passw),
                    new PyString(namespace),
                    new PyString(URL),
                    new PyString(api_level)
            PyObject ExampleApiObject = ExampleApiClass.__call__(arguments);
            return (ExampleApiJavaType) ExampleApiObject.__tojava__(ExampleApiJavaType.class);

My type is here:

    // Java interface for a building object
    public interface ExampleApiJavaType{
        public void start_session();
        public void stop_session();
        public String get_related(String article_id);
        public String get_company(String tickerid);
        public void save_last_results_to_disk(String filename);
        public String get_article(String query_string);

I used the example from the book 

Using jython-standalone-2.7-b2 with jdk1.7.0_51

Attached is a complete example. (also found here

Also see related case
msg9917 (view) Author: Jim Baker (zyasoft) Date: 2015-04-20.21:09:41
This should have been just fixed, the root cause of #1795 is almost certainly a duplicate

Could you please try out the latest RC3 when it's published shortly (hopefully tonight!), or against trunk?
Date User Action Args
2015-04-28 16:07:32zyasoftsetstatus: pending -> closed
2015-04-20 21:09:41zyasoftsetstatus: open -> pending
resolution: duplicate
messages: + msg9917
nosy: + zyasoft
2014-07-24 14:53:55brianraycreate