Question

Situation: I wish to send an array of objects (of different types) from a client to a server using ObjectOutputStream.

Problem : The Object array is not serializable (I get a NotSerializable Exception).

What I tried: I created a dummy class that extends Object, and implements Serializable. But I cannot cast the original objects array to this class.

Is there any way to serialize an array of Objects ?

Was it helpful?

Solution

It should not be any serialization problems with Object[].

Arrays are Serializable in Java, even when the array element type is not (probably because array may theoretically hold instances of some derived Serializable class instead).

Most likely, one of the members of your array is not serializable. The stack trace should tell this, check it.

OTHER TIPS

I recommend you to encode array by base64 and send it to server. then, in there you can decode it easily.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top