Thanks very much for the example and suggestions.  Unfortunately, I have no control over how the data are serialized.


Would you mind also providing an example of depickling from within Java (i.e. using the jython jar)?  This is really the usage I’m trying to get running, and I’ve had a very tough time.


Thanks again,



Ulises Melendez

From: Stefan Eischet []
Sent: Thursday, August 07, 2008 3:05 AM
To: Melendez,Ulises
Subject: Re: [Jython-users] Unpickling from Java


Hello Ulises,


to confirm that the basics work, I've just tried unpickling a simple tuple successfully:


$ python

Python 2.5.1 (r251:54863, Apr 15 2008, 22:57:26) 

[GCC 4.0.1 (Apple Inc. build 5465)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> import pickle

>>> data = (1,2,3,4,5,)

>>> pickle.dumps(data)


>>> ^D


$ jython

Jython 2.5a1+ (asm:4943:4945, Jul 15 2008, 15:30:04) 

[Java HotSpot(TM) Client VM (Apple Inc.)] on java1.5.0_13

Type "help", "copyright", "credits" or "license" for more information.

>>> import pickle

>>> pickle.loads('(I1\nI2\nI3\nI4\nI5\ntp0\n.')

(1, 2, 3, 4, 5)

>>> ^D


YMMV with other Jython versions, of course. Two things you might want to look at are the protocol parameter of the pickle module (which defaults to 0, and which should be fine... see There's also a discussion about certain problems and workarounds for floating point values:


What I usually do instead of pickling is to serialize/deserialize simpler data structures (mainly dicts) into JSON: and read them from Java code. So, instead of pickling an object I just dump its interesting properties into a dict and read them back from the dict representation when needed. This also works fine when using plain Java instead of Java+Jython. Maybe you'll have more success with that approach.





On 2008-08-07, at 02:10 , Melendez,Ulises wrote:

I have a python object that’s been pickled to a file, and I need to unpickle it from within a Java VM.  I’ve searched around and fooled around with cPickle (.java), but I’m having no such luck.  Can anyone point me to an example of unpickling a pickled object within Java?  I can also provide some of my failed attempts for public ridicule, if that would help.


Thanks in advance,



Ulises Melendez


This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
Jython-users mailing list