From: Ranjan B. <ran...@fr...> - 2002-01-27 04:32:14
|
Hi -- Is there any magic I need to do to make Jython objects deserialize correctly? I was experimenting with having a Jython class implement Serializable -- to be honest, I expected to see it blow up when I sent it to an ObjectOutputStream -- but that worked. However, when I deserialize it, I get a ClassNotFound exception. Here's the code: import java class MyClass(java.io.Serializable): def __init__(this, x): this.x = x obj = MyClass(33) baos = java.io.ByteArrayOutputStream() oos = java.io.ObjectOuputStream(baos) oos.writeObject(obj) ## good so far ois = java.io.ObjectInputStream(java.io.ByteArrayInputStream(baos.toByteArray())) ois.readObject() Traceback (innermost last): File "<console>", line 1, in ? java.lang.ClassNotFoundException: org.python.proxies.__main__$MyClass$0 at java.net.URLClassLoader$1.run(URLClassLoader.java:201) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:189) at java.lang.ClassLoader.loadClass(ClassLoader.java:308) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268) at java.lang.ClassLoader.loadClass(ClassLoader.java:264) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:324) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:212) at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:546) at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1491) at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1413) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1604) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1252) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:323) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:42) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:28) at java.lang.reflect.Method.invoke(Method.java:313) at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java ) at org.python.core.PyMethod.__call__(PyMethod.java) at org.python.core.PyObject.__call__(PyObject.java) at org.python.core.PyInstance.invoke(PyInstance.java) at org.python.pycode._pyx11.f$0(<console>:1) at org.python.pycode._pyx11.call_function(<console>) at org.python.core.PyTableCode.call(PyTableCode.java) at org.python.core.PyCode.call(PyCode.java) at org.python.core.Py.runCode(Py.java) at org.python.core.Py.exec(Py.java) at org.python.util.PythonInterpreter.exec(PythonInterpreter.java) at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java) at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java) at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java) at org.python.util.InteractiveConsole.push(InteractiveConsole.java) at org.python.util.InteractiveConsole.interact(InteractiveConsole.java) at org.python.util.jython.main(jython.java) java.lang.ClassNotFoundException: java.lang.ClassNotFoundException: org.python.proxies.__main__$MyClass$0 Any hints -- my suspicion is that it's something deep in the java security mechanism... Ranjan |
From: Samuele P. <ped...@bl...> - 2002-01-27 12:52:53
|
Hi. You should use a org.python.util.PythonObjectInputStream to read that back. Anyway it is important that your class is defined at the top-level in a module that is not the main module (that one you pass on the jython command line), this are basicly the same rules for pickle, which OTOH does not support even under jython java classes and not completely python subclasses of java classes. regards, Samuele Pedroni. ----- Original Message ----- From: Ranjan Bagchi <ran...@fr...> To: <jyt...@li...> Sent: Sunday, January 27, 2002 5:32 AM Subject: [Jython-users] Serializable classes > Hi -- > > Is there any magic I need to do to make Jython objects deserialize correctly? I was experimenting with having a Jython class implement Serializable -- to be honest, I expected to see it blow up when I sent it to an ObjectOutputStream -- but that worked. > > However, when I deserialize it, I get a ClassNotFound exception. > > Here's the code: > > import java > class MyClass(java.io.Serializable): > def __init__(this, x): > this.x = x > > obj = MyClass(33) > baos = java.io.ByteArrayOutputStream() > oos = java.io.ObjectOuputStream(baos) > oos.writeObject(obj) > ## good so far > ois = java.io.ObjectInputStream(java.io.ByteArrayInputStream(baos.toByteArray())) > ois.readObject() > Traceback (innermost last): > File "<console>", line 1, in ? > java.lang.ClassNotFoundException: org.python.proxies.__main__$MyClass$0 > at java.net.URLClassLoader$1.run(URLClassLoader.java:201) > at java.security.AccessController.doPrivileged(Native Method) > at java.net.URLClassLoader.findClass(URLClassLoader.java:189) > at java.lang.ClassLoader.loadClass(ClassLoader.java:308) > at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268) > at java.lang.ClassLoader.loadClass(ClassLoader.java:264) > at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:324) > at java.lang.Class.forName0(Native Method) > at java.lang.Class.forName(Class.java:212) > at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:546) > at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1491) > at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1413) > at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1604) > at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1252) > at java.io.ObjectInputStream.readObject(ObjectInputStream.java:323) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:42) > at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.ja va:28) > at java.lang.reflect.Method.invoke(Method.java:313) > at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java > ) > at org.python.core.PyMethod.__call__(PyMethod.java) > at org.python.core.PyObject.__call__(PyObject.java) > at org.python.core.PyInstance.invoke(PyInstance.java) > at org.python.pycode._pyx11.f$0(<console>:1) > at org.python.pycode._pyx11.call_function(<console>) > at org.python.core.PyTableCode.call(PyTableCode.java) > at org.python.core.PyCode.call(PyCode.java) > at org.python.core.Py.runCode(Py.java) > at org.python.core.Py.exec(Py.java) > at org.python.util.PythonInterpreter.exec(PythonInterpreter.java) > at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java) > at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java) > at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java) > at org.python.util.InteractiveConsole.push(InteractiveConsole.java) > at org.python.util.InteractiveConsole.interact(InteractiveConsole.java) > at org.python.util.jython.main(jython.java) > > java.lang.ClassNotFoundException: java.lang.ClassNotFoundException: org.python.proxies.__main__$MyClass$0 > > > Any hints -- my suspicion is that it's something deep in the java security mechanism... > > Ranjan > > > > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > |