473,748 Members | 2,602 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# vs Java Serialization

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? How do I determine
exactly what the serialized data looks like, both
theoretically and emperically? I'd like to be able to
view it at the byte level just for general debugging
purposes. (Of course I could use a packet sniffer, but
that's a little too gross even for a hardware person like
me!)

Thanks,
Ray Mitchell
Nov 15 '05 #1
1 3316
You have the choice of several serialization formats in C#. No matter which
format you decide to use, you can save the serialized data to a file if you
want to have a look at the structure. The XML serializer creates quite
straightforward , easy to interpret output. The binary serializer requires a
hex editor to play around with of course.

Try something like this:

using System;
using System.IO;
using System.Xml.Seri alization;
using System.Collecti ons;
namespace Test
{
[Serializable()]
public class Config
{
const string filename = "C:\\Temp\\conf ig.xml";
private string userID;
public string UserID
{
get { return userID; }
set { userID = value; }
}
public void Save()
{
XmlSerializer ser = new XmlSerializer(t ypeof(Config));

TextWriter writer = new StreamWriter(fi lename);
ser.Serialize(w riter, this);
writer.Close();
}
public static Config GetConfig()
{
Config cfg;
FileStream fs;
try
{
fs = new FileStream(file name, FileMode.Open);
/* Use the Deserialize method to restore the object's state
with
data from the XML document. */
XmlSerializer ser = new XmlSerializer(t ypeof(Config));
cfg = (Config) ser.Deserialize (fs);
fs.Close();
}
catch
{
cfg = null;
}
return cfg;
}
}
}

Then use this object from a test program something like this

Config cfg = new Config();
cfg.UserID = "MyTestID";
cfg.Save(); // Look how it is saved in C:\Temp\Config. xml
// ...
Config cfgNew = Config.GetConfi g();

I'm not sure about compatibility between Java and C# serialization formats,
but hopefully someone else in the newsgroup can answer that.

Eric

"Ray Mitchell" <Ra************ ***********@Mea nOldTeacher.com > wrote in
message news:07******** *************** *****@phx.gbl.. .
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? How do I determine
exactly what the serialized data looks like, both
theoretically and emperically? I'd like to be able to
view it at the byte level just for general debugging
purposes. (Of course I could use a packet sniffer, but
that's a little too gross even for a hardware person like
me!)

Thanks,
Ray Mitchell


Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
3313
by: DJ Dev | last post by:
Hi All, I have to build a web application for my project. This web application will be basically calling some functions written in C/C++. Basically, the process involves getting user input file, passing the file information to the C/C++ function, Getting the result from C/C++ function etc. Ultimate aim will be to create a web service using WSDL, XML etc. It's actually more complex than it sounds.
2
3004
by: Ante Sabo | last post by:
Hello, It seems to me to be in some kinda trouble. I wanted to implement communication between Java applet and Server through sockets and Serialization. So, I serialize Object, send it to server which deserialize it with no problems. In other direction problems came out since Object serialized under Java 1.4.1 seems to be not deserializable under Java 1.1.4. (MS VM). If applet si run under J2, there are no problems, but I cannot push...
2
8774
by: Krzysztof Paz | last post by:
Hi, There is a Java (SUN 1.4) server which using Object Input/Output Streams at SSL/Socket to communicate with Java clients. Now there is a request for making C# Client for this server also. SSL layer could be done with Org.Mentalis.Security.dll from seclib-1.0 Mentalis package - its fine... But, threre is a problem: How to properly communicate from C# language to Java.ObjectInputStream - cause I've tried many times, and always get the...
0
2502
by: umhlali | last post by:
I get the following exception when my VB.NET app calls a Java web service that returns an array of objects. The same call works for a single object though. So looks like there is no problem serializing the object but there seems to be a problem serializing an array of objects. Any help will be appreciated "Cannot assign object of type System.Object to an object of type ElectronicWallet.C2PTest.PaymentItem." :...
1
4170
by: Vaibhav Modak | last post by:
Hi All, I have a Web Service written in Java (Web Logic) and I am trying to call it in my ASP. NET client. I am facing a problem while getting the data from the Web Service Method. My Web Service returns me an object which is a wrapper around an array of objects. (Earlier I was trying to read the array directly but could not succeed - so I wrapped that array with another object.) Now the primary issue is regarding the chunky characters...
2
2758
by: yqlu | last post by:
I hava developed a client in C# that is connected to a 3-party XML Web Services developed in Java based on the AXIS 1.1. Most methods call are successful except for one method named "findObjects" and return a complex type "FieldSearchResult". The error message as following : "Cannot assign object of type System.String to an object of type System.String. There is an error in XML document (23, 97)." By the way,I hava written a client in Java...
2
6964
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip
2
3966
by: tiberiu.motoc | last post by:
Hi. I've asked this question on the MSDN forums, but I've had no replies. I'm really stuck, so I'm gonna try my luck here. I have a Java web service which contains a simple function; the function returns a double-dimensional array of integers. I ran the wsdl utility and I created a simple .NET web client which calls the function. I noticed that the result is returned as a jagged array, since multi-dimensional arrays cannot be...
0
8823
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9530
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8237
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.