Java vs C# Serialization

R

Ray Mitchell

Hello,

I have two Java applications that exchange serialized objects. Although I
would like to ultimately convert both to C# it's a pretty monumental task,
especially for someone just learning both langauges. I thought it might be
more reasonable to start with simply converting the simpler one of the two
and getting it to work. I have used Microsoft's free Java to C# converter
to convert most of the code, but of course I must complete some of the
conversions manually. I have this basic concern, however: Will the
serialization done in C# be the same as that done in Java? Also, do all
Java compilers serialize the same way for the same source code?

Thanks,
Ray Mitchell
 
M

Mark Thornton

Mike said:
Yes. Java serialization is defined precisely.

However the calculation of the serialVersionUID is not so well defined.
The problem is that the calculation includes synthetic members whose
existence and name can be compiler dependent.

Mark Thornton
 
M

Mike Schilling

Mark Thornton said:
However the calculation of the serialVersionUID is not so well defined.
The problem is that the calculation includes synthetic members whose
existence and name can be compiler dependent.

Ouch! That can be a problem even across different versions of the same
compiler.

IMHO, if you're going to serialize a class, you should define
serialVersionUID explicitly. That allows you to control if and when
persistent compatibility is broken.
 
M

Mark Thornton

Mike said:
Ouch! That can be a problem even across different versions of the same
compiler.

IMHO, if you're going to serialize a class, you should define
serialVersionUID explicitly. That allows you to control if and when
persistent compatibility is broken.

I agree, explicitly defining serialVersionUID is now all but essential.
The documentation and tutorials should be updated to reflect this. The
version of Java (1.5) will introduce quite a few more synthetic methods,
so anything that hasn't defined serialVersionUID risks being broken.

Mark Thornton
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top