سؤال

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 ?

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top