0

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 ?

1

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi Mr. Meskauskas. You were right. I cast one of the elements to a string object, and it worked.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.