Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I serialize a Java object such that it can be deserialized by pickle (Python)?

I'm using a Python service that uses pickled messages as part of its protocol. I'd like to query this service from Java, but to do so, I need to pickle my message on the client (Java). Are there any implementations of pickle that run on the JVM (ideally with minimal dependencies)?

Clarification: Modifying the server side is not an option, so while alternate serializations would be convenient, they won't solve the problem here.

like image 499
Seth Fitzsimmons Avatar asked Sep 26 '11 16:09

Seth Fitzsimmons


People also ask

How do I serialize an object in Java?

To make a Java object serializable we implement the java. io. Serializable interface. The ObjectOutputStream class contains writeObject() method for serializing an Object.

Which of these methods in the pickle module can be used to de serialize an object?

To serialize an object hierarchy, you simply call the dumps() function. Similarly, to de-serialize a data stream, you call the loads() function.


2 Answers

Some additional investigation yielded pyrolite, an MIT-licensed library that allows Java and .NET programs to interface with the Python world. In addition to remote object functionality, it (more importantly) includes a pickle serializer and de-serializer.

like image 116
Seth Fitzsimmons Avatar answered Sep 18 '22 15:09

Seth Fitzsimmons


You can use a Java JSON serializer like GSON or Jackson to serilaise quite easily and use a python json pickle to deserialize

like image 28
sfk Avatar answered Sep 20 '22 15:09

sfk