{"action":"created","issue":{"url":"https://api.github.com/repos/bartdag/py4j/issues/171","labels_url":"https://api.github.com/repos/bartdag/py4j/issues/171/labels{/name}","comments_url":"https://api.github.com/repos/bartdag/py4j/issues/171/comments","events_url":"https://api.github.com/repos/bartdag/py4j/issues/171/events","html_url":"https://github.com/bartdag/py4j/issues/171","id":104571781,"number":171,"title":"Serializing a Python Class Implementing a Java Interface for py4j version 0.8.2.1","user":{"login":"Py4JQuestionAsker","id":14099358,"avatar_url":"https://avatars.githubusercontent.com/u/14099358?v=3","gravatar_id":"","url":"https://api.github.com/users/Py4JQuestionAsker","html_url":"https://github.com/Py4JQuestionAsker","followers_url":"https://api.github.com/users/Py4JQuestionAsker/followers","following_url":"https://api.github.com/users/Py4JQuestionAsker/following{/other_user}","gists_url":"https://api.github.com/users/Py4JQuestionAsker/gists{/gist_id}","starred_url":"https://api.github.com/users/Py4JQuestionAsker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Py4JQuestionAsker/subscriptions","organizations_url":"https://api.github.com/users/Py4JQuestionAsker/orgs","repos_url":"https://api.github.com/users/Py4JQuestionAsker/repos","events_url":"https://api.github.com/users/Py4JQuestionAsker/events{/privacy}","received_events_url":"https://api.github.com/users/Py4JQuestionAsker/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-09-02T21:09:23Z","updated_at":"2015-09-02T23:44:08Z","closed_at":null,"body":"Hi,\r\n\r\nWhen I try to Serialize an instance of a class implementing Serializable, my code fails because serialization checks are made by using instanceof (see line 1166 of the ObjectOutputStream source code: http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/io/ObjectOutputStream.java) and PythonProxyHandler is not an instance of Serializable. A very \r\nsimple example that fails on Pyspark is:\r\n```\r\nclass SomeSerializable(object):\r\n    class Java:\r\n        implements = ['java.io.Serializable']\r\nbyteStream=sc._jvm.java.io.ByteArrayOutputStream()\r\nobjectStream=sc._jvm.java.io.ObjectOutputStream(byteStream)\r\nobjectStream.writeObject(SomeSerializable())\r\n```\r\ngiving the stack trace\r\n\r\n```\r\nPy4JJavaError                             Traceback (most recent call last)\r\n<ipython-input-7-fc2ce1ad2487> in <module>()\r\n----> 1 objectStream.writeObject(a)\r\n\r\n/homes/breese/testroot/share/spark/python/lib/py4j-0.8.2.1-src.zip/py4j/java_gateway.py in __call__(self, *args)\r\n    536         answer = self.gateway_client.send_command(command)\r\n    537         return_value = get_return_value(answer, self.gateway_client,\r\n--> 538                 self.target_id, self.name)\r\n    539 \r\n    540         for temp_arg in temp_args:\r\n\r\n/homes/breese/testroot/share/spark/python/lib/py4j-0.8.2.1-src.zip/py4j/protocol.py in get_return_value(answer, gateway_client, target_id, name)\r\n    298                 raise Py4JJavaError(\r\n    299                     'An error occurred while calling {0}{1}{2}.\\n'.\r\n--> 300                     format(target_id, '.', name), value)\r\n    301             else:\r\n    302                 raise Py4JError(\r\n\r\nPy4JJavaError: An error occurred while calling o23.writeObject.\r\n: java.io.NotSerializableException: py4j.reflection.PythonProxyHandler\r\n\tat java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)\r\n\tat java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)\r\n\tat java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)\r\n\tat java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)\r\n\tat java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)\r\n\tat java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\r\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\r\n\tat java.lang.reflect.Method.invoke(Method.java:483)\r\n\tat py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:231)\r\n\tat py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:379)\r\n\tat py4j.Gateway.invoke(Gateway.java:259)\r\n\tat py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133)\r\n\tat py4j.commands.CallCommand.execute(CallCommand.java:79)\r\n\tat py4j.GatewayConnection.run(GatewayConnection.java:207)\r\n\tat java.lang.Thread.run(Thread.java:745)\r\n```\r\nMy py4j version is 0.9."},"comment":{"url":"https://api.github.com/repos/bartdag/py4j/issues/comments/137274746","html_url":"https://github.com/bartdag/py4j/issues/171#issuecomment-137274746","issue_url":"https://api.github.com/repos/bartdag/py4j/issues/171","id":137274746,"user":{"login":"Py4JQuestionAsker","id":14099358,"avatar_url":"https://avatars.githubusercontent.com/u/14099358?v=3","gravatar_id":"","url":"https://api.github.com/users/Py4JQuestionAsker","html_url":"https://github.com/Py4JQuestionAsker","followers_url":"https://api.github.com/users/Py4JQuestionAsker/followers","following_url":"https://api.github.com/users/Py4JQuestionAsker/following{/other_user}","gists_url":"https://api.github.com/users/Py4JQuestionAsker/gists{/gist_id}","starred_url":"https://api.github.com/users/Py4JQuestionAsker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Py4JQuestionAsker/subscriptions","organizations_url":"https://api.github.com/users/Py4JQuestionAsker/orgs","repos_url":"https://api.github.com/users/Py4JQuestionAsker/repos","events_url":"https://api.github.com/users/Py4JQuestionAsker/events{/privacy}","received_events_url":"https://api.github.com/users/Py4JQuestionAsker/received_events","type":"User","site_admin":false},"created_at":"2015-09-02T23:44:08Z","updated_at":"2015-09-02T23:44:08Z","body":"Yes, though broadcast variables provide a method to share them across machines provided they are read-only. That being said, any official solution offered in Py4J would be much more convenient, it is something I would greatly appreciate."}}