From: Brian r. <re...@bu...> - 2014-07-24 14:54:03
|
New submission from Brian ray: I get the following exception: > Exception in thread "main" java.lang.ClassCastException: > org.python.core.PySingleton cannot be cast to > com.xxx.yyyy.Example.ExapleApiJavaType This happens when I call 'return (ExampleApiJavaType) ExampleApiObject.__tojava__(ExampleApiJavaType.class)', full code here: package com.xxx.yyyy.example; import com.xxx.yyyy.example.ExampleApiJavaType; 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 package com.xxx.yyyy.example; 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 http://www.jython.org/jythonbook/en/1.0/JythonAndJavaIntegration.html#one-to-one-jython-object-factories Using jython-standalone-2.7-b2 with jdk1.7.0_51 Attached is a complete example. (also found here https://github.com/brianray/embedded-jython) Also see related case http://bugs.jython.org/issue1103 ---------- components: Core messages: 8886 nosy: brianray severity: major status: open title: __tojava__ does not support cast to user derived class versions: Jython 2.7 _______________________________________ Jython tracker <re...@bu...> <http://bugs.jython.org/issue2181> _______________________________________ |