Reputation: 324
I'm using a 3rd party tool of objectPlanet called easyChart to produce graphical chart. They provide a jar lib called Chart.jar and ChartServer.jar
I write an easyChart object on server side:
Chart chart = new BarChart();
... <create chart data here> ...
ByteArrayOutputStream bStream = new ByteArrayOutputStream();
ObjectOutputStream oStream = new ObjectOutputStream( bStream );
oStream.writeObject (chart);
byte[] byteVal = bStream.toByteArray();
String chartInString = Base64.encode(byteVal);
and read it back on client side:
byte[] readByte = Base64.decode(chartInString);
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(readByte));
Chart chart = (Chart) ois.readObject();
It works fine when server and client has same JVM version. I realize that GenericChart implements Serialization (this class is inside the jar provided).
How I can overcome this matter since I can't modify their provided jar classes?
Much appreciate any reply. Thank you!
Upvotes: 1
Views: 1363
Reputation: 310883
There is a warning in the class Javadoc of every Swing class in existence that serialized versions will not be compatible with other JDK versions. So, don't serialize them. Serialize the models.
Upvotes: 1
Reputation: 43728
I can't read the Chart object, it throws this exception: java.io.InvalidClassException: javax.swing.JComponent; local class incompatible: stream classdesc serialVersionUID = -1030230214076481435, local class serialVersionUID = 5670834184508236790
Actually, this is not related to the JVM version but to the run time library. The class javax.swing.JComponent
was changed in a way that makes the serial representation incompatible.
I am afraid, there is not much you can do about it apart from using the same version.
Upvotes: 1