amitsarangi / mt4j

Automatically exported from code.google.com/p/mt4j
GNU General Public License v2.0
0 stars 0 forks source link

Can't use xstream with Vector3D and subclasses. #28

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago

I'm using xstream to serialize the state of an MT4j application. Deserialized 
instances of Vector3D and Vertex objects do not test equal to the original 
objects. Attached is a very simple JUnit test case which demonstrates the 
problem.

I found that the reason for this is that xstream bypasses the constructors 
entirely, so "type" never gets set.  The field "type" is declared transient and 
xstream ignores transient fields.

I recommend deleting the type field from Vector3D altogether and giving 
Vector3D and its subclasses robust hashCode() and equals() methods. I've 
attached versions of Vector3D, Vertex, and BezierVertex that have these.

Any code that calls getType() can simply use "instanceof" instead.    

Original issue reported on code.google.com by drran...@gmail.com on 21 Apr 2011 at 7:14

Attachments:

GoogleCodeExporter commented 9 years ago
I made a typo in BezierVertex.java, so I'm attaching the corrected version.

Original comment by drran...@gmail.com on 21 Apr 2011 at 7:17

Attachments: