Serialization Problems and books on serialization?

S

sinleeh

I was trying to do serialization but have problems writing object with
ObjectOutputStream.writeObject().

The problem is that ObjectOutputStream.writeObject() sometimes fails
the serialize object mysteriously. It serialize objectA by itself OK,
but when you use objectA as data member of objectB and serialize
objectB, it fails.

My latest problem is about serializing a java.util.List of String. When
the said list is a data member in objectA, serialization OK. However,
when I put objectA inside objectB and serialize objectB, serialization
failed unless I remove the List of String in objectA.

The problem is not unique to list of string and it is known to happen
on other objects.

I am pretty sure it is something I did but just cannot figure out how.
Can anyone point out how to solve this problem or a workaround?

Also, can someone recommend a book on serialization.

Many thanks in advance.

Sinlee Huang.
P.S. Please reply to this newsgroup only coz I do not check the hotmail
account I am using
 
M

Michael Borgwardt

I was trying to do serialization but have problems writing object with
ObjectOutputStream.writeObject().

The problem is that ObjectOutputStream.writeObject() sometimes fails
the serialize object mysteriously. It serialize objectA by itself OK,
but when you use objectA as data member of objectB and serialize
objectB, it fails.

How exactly does it "fail"?
 
S

sinleeh

How exactly does it "fail"?

That's the strange thing. The function call never return. In other
words, it hangs the program. There are no significant CPU activity.

The following is the code sniplet for serialization used. model1 is the
objectB on previous message.

PipedOutputStream out = new PipedOutputStream();
PipedInputStream in = new PipedInputStream(out);
ObjectOutputStream oos = new ObjectOutputStream(out);
oos.writeObject(model1);

It does not like the last line.

Just in case it's relevent, I am using Sun's java SDK 1.4.2
Thank you in advance
Sinlee
 
M

Michael Borgwardt

That's the strange thing. The function call never return. In other
words, it hangs the program. There are no significant CPU activity.

The following is the code sniplet for serialization used. model1 is the
objectB on previous message.

PipedOutputStream out = new PipedOutputStream();
PipedInputStream in = new PipedInputStream(out);
ObjectOutputStream oos = new ObjectOutputStream(out);
oos.writeObject(model1);

It does not like the last line.

I suspect that it has nothing to do with serialization at all and
that your write call just blocks because the buffer of the PipedInputStream
is full. You have to read it in a different thrad. If that's not it,
make an SSCCE: http://www.physci.org/codes/sscce.jsp
 
S

sinleeh

Many Thanks for the info. It is a new lead for me. I will try to
investigate the buffer issue. Will probably takes some time. I will of
course report back when its done.

Best regards,
Sinlee
 
S

sinleeh

I should add that what you suggests make sense because the problematic
serialization occurs generally on larger composite objects.

Your reply had lead me to think about how I serialize very large
object. upon inspection of the code, I see that I actually use
ByteArrayOutputStream and ByteArrayInputStream for very large object.
Will replace Piped*Stream with them and see what happens.
Best regards,
Sinlee
 
S

Sudsy

That's the strange thing. The function call never return. In other
words, it hangs the program. There are no significant CPU activity.

The following is the code sniplet for serialization used. model1 is the
objectB on previous message.

PipedOutputStream out = new PipedOutputStream();
PipedInputStream in = new PipedInputStream(out);
ObjectOutputStream oos = new ObjectOutputStream(out);
oos.writeObject(model1);

It does not like the last line.

Since I don't see any code (should be a separate thread) reading the
pipe, I'd guess that you're filling up the pipe. The capacity is not
infinite and you're probably blocking on the write.
 
S

sinleeh

Dear Sudsy, Michael,

Indeed as both of you spotted, my problem is with buffer. I changed to
ByteArrayStreams (whose buffers can grow with data) and everything go
away.

Many thanks for your help.

Best regards,
sinlee
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top