Base64 encoder with serialized JFreeChart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
msprauer
Posts: 7
Joined: Wed Jul 11, 2007 5:02 pm

Base64 encoder with serialized JFreeChart

Post by msprauer » Thu Jul 12, 2007 1:30 pm

I have been having problems with the deserialization of an encoded serialized JFreeChart object.

Here's the scoop:

I am serializing a JFreeChart instance, and encapsulating it in an application using the base64 encoder in the org.jfree.xml.util library. Later on, when the JFreeChart instance needs to be used again, I decode the data (using the base64 decoder), write out the data as a file, then try to deserialize it.

Doing some initial investigative work, it appears to me that the original serialized JFreeChart file and the resulting decoded file are different (Their sizes are the same, although diffing them shows minor differences here and there), and I am unable to deserialize it correctly.

Anyone experience this? Does the base64 encoder have a problem with binaries?

jcommon-1.0.9
jcommon-xml-1.0.9
jfreechart-1.0.5

msprauer
Posts: 7
Joined: Wed Jul 11, 2007 5:02 pm

Post by msprauer » Thu Jul 12, 2007 2:48 pm

If it helps any, this is the actual error I get:

org.jfree.chart.plot.Plot; local class incompatible: stream classdesc serialVersionUID = -8831571430103695388, local class serialVersionUID = -8831571430103671324


Which doesn't make sense to me because the object that was serialized was JFreeChart object?

This is the line of code where it barfs:

JFreeChart chart;
chart = (JFreeChart)in.readObject();


Keep in mind that the serialized JFreeChart object had been encoded using the base64 encoder, then decoded, written out to a file, and is now being deserialized.

Taqua
JFreeReport Project Leader
Posts: 698
Joined: Fri Mar 14, 2003 3:34 pm
Contact:

Post by Taqua » Thu Jul 12, 2007 4:21 pm

Hi,

this is not necessarily a error in the decoder. This sounds more or less like you are deserializing the chart-object on a different system with different versions of the library. The serialVersionUID of -8831571430103671324 is the declared Id in the sources of JFreeChart (since version 1.0.0-rc1).

So the serialized object is most likely very old and was created with an pre 1.0.0 version of JFreeChart. Serialized objects do not survive structural changes to their underlying classes - that's why no one is using them for long term storage.

Have fun,
said Thomas

msprauer
Posts: 7
Joined: Wed Jul 11, 2007 5:02 pm

Post by msprauer » Thu Jul 12, 2007 5:13 pm

Thank you for your feedback, however I'm not entirely sure that's the case.

I have successfully serialized and deserialized a JFreeChart instance, without any encoding. But when the encoder is used, in this order:
serialize
encode
decode
deserialize

It won't properly deserialize. I am not trying to deserialize an old JFreeChart instance either. I have written a test app that does this logic as seen above, and still I can't get it to work (The code is proprietary, otherwise I would post it).

It may be worth noting that I have also tried a different encoder, and still get this same error. With this in mind, I would agree it may not be the encoder.

Any other thoughs?

msprauer
Posts: 7
Joined: Wed Jul 11, 2007 5:02 pm

Post by msprauer » Fri Jul 13, 2007 2:52 pm

Just to note, this has been resolved. It turned out that it is in fact Base64 encoding. I used an ASCII85 encoder and it worked fine.

Thanks for you help.

Locked