2

I have an OBJECT ARRAY, how can i serialize this array? I give you c# code and i have to write in java. Thanks. C#:

byte[] data = JSon.Serialize<object[]>(Parameters);

Please note that i want to serialize an array which has objects.. i realize that is not the exact answer:

ObjectOutputStream out = new ObjectOutputStream(anyOutputStream);
out.writeObject(objectArray);

i have a problem with anyOutputStream, i really don't know what i should place on parameter..

3
  • I think it's already answered here: stackoverflow.com/questions/4262390/… Commented Jul 31, 2013 at 10:12
  • Use any of the existing JSON API's, for example Jackson Commented Jul 31, 2013 at 10:14
  • Overview of JSON API's for Java here Commented Jul 31, 2013 at 10:16

2 Answers 2

4

If the object array contains Serializable objects then you can use java.io.ObjectOutputStream

ObjectOutputStream out = new ObjectOutputStream(anyOutputStream);
out.writeObject(objectArray);
...
Sign up to request clarification or add additional context in comments.

1 Comment

i have error with "anyOutputStream".. i don't know what i should replace with
1

new JSONObject(parameters).toString().getBytes()

requires JSONObject

2 Comments

i have this error message: The constructor JSONObject(Object[]) is undefined, any idea?
Clearly, you need a JSONArray if you're going to serialize an array. However, there's no guarantee it will work---it all depends on what the framework can do with your array elements.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.