Ok, I'm really confused here. I know that the only way to transfer objects via input/output streams is if they are serialised. If i wanted to transfer objects of my Person class from my client to server, I would have to implement "serializable" in my Person class. That's all well and good.

But what if we're dealing with an object that isn't serializable, an object of a class I didn't create?

How do I transfer such an object? Seems unlikely that I won't be able to do so. I need to transfer a particular object from point A to B and the object cannot be serialized. Please, how do I do this?

Is the class not serialisable because the writer didn't declare it as such, or is there some real reason why it cannot be serialised? Most classes that just contain ordinary data can be serialised - it's normally only a problem if they have handles into non-Java stuff in the operating system, or complex thread/state information.
If its the former you could try creating your own trivial subclass of the class and declaring that serialisable and use it instead of the original class.
Otherwize you will have to get() all the instance variables for the object and write them one at a time across the stream

AFAIK, you have two options:

  • Use an alternative Java serialization implementation like Jboss Serialization which AFAIK doesn't require your classes to implement Serializable or Externalizable
  • In case you are concerned more about interoperability than speed, use something along the lines of Xstream or Protobuf

sorry, ive been really busy. Yeah, i managed to break down the object into a bunch of byte arrays and send them over the network, then reassembled them lol your methods are probably better, but ill stick to this for now for my project. But along the line im definitely taking your advices.

This question has already been answered. Start a new discussion instead.