Jump to content
  • Advertisement
Sign in to follow this  
axv4745

Java Serialization

This topic is 4826 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does anyone know if Java can serialize objects with cross references (e.g. ClassA references ClassB and vice versa)? I'm trying to serialize an object of ClassA across the network and it fails to serialize one of it's references (i.e. ClassB). However when I try serialize an object of ClassB if fails to serialize its reference of ClassA. If anyone can offer any insight on this that would great.

Share this post


Link to post
Share on other sites
Advertisement
Yes it can.

But both ClassA and ClassB have to be serializable. Otherwise it just ain't gonna work.

Oh yes, and the application on the other end needs to have ClassA and ClassB both in scope (i.e. visible to the loader), otherwise it'll be unserialising a nonexistent class, which doesn't work.

If you're using some kind of jar file optimiser or obfuscator, be sure that it doesn't optimise ClassB out.

What exception is it throwing?

Mark

Share this post


Link to post
Share on other sites
both times it throws a ClassNotFoundException where the class not found is the object each is trying to reference (in this case each other). I looked over my code many times and I'm pretty sure each is implementing the Serializable interface (as well any innerclasses that are in the files). Plus I'm pretty sure that the applications on both end have the two classes. I'm not sure if I'm using a jar file optimiser or obfuscator. The thing is that I am using a pre-built framework to do my project so its possible that it is using this form of mechanism and I am just not aware of it. How can I found out if ClassB is being optimized out?

Share this post


Link to post
Share on other sites
if you are using all default stuff like the standard netbeans setup, you aren't using an obfuscator, i guess. does the ClassNotFoundException not mention which class is causing problems?

Share this post


Link to post
Share on other sites
Classes are never normally optimised out in Java.

Ensure that you are using identical versions of the application at both ends - ensure that the class files are the same.

Ideally, distribute client and server in the same .jar and just run with different parameters. Make sure they're the same version.

Mark

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!