Java C# Bridge is a tool for Serlializing/Deserlializing between Java object and C# object.
Features

easy to use. it has only few APIs you need to known.

compact. because it serializes the object to binary stream directly, it reduces much bandwidth than XML format.

high speed. because it manipulates the binary stream directly, it avoids some reflecting operations. it is faster than serlizition to XML format.

 

Tutorial

HelloWorld hello = new HelloWorld();

hello can be:

  a. an object;

  b. a java.util.List implemention(Java) or a System.Collections.IList implemention(C#)

  c. a single dimension or multi-dimension array (java) or a single dimension or a jagged array (c#)

  d. a java.util.Map implemention(Java) or a System.Collections.IDictionary implemention(C#)

  e. a primitive/primitive wrapper object (Java,C#)

  f. a java.util.Date object (Java) or a DateTime object (C#)

  g. a String (Java,C#)

  h. null (Java,C#)


Java:

code:

HelloWorld hello = new HelloWorld();

//here hello is a pojo with default constructor.

/*Serlize to binary stream*/

ToByteConvertHelper toBytes = new ToByteConvertHelper();

byte[] resultByte=toBytes.toByte(source);



/*Deserlize from binary stream*/

FromByteConvertHelper fromBytes = new FromByteConvertHelper();

HelloWorld hello2=(HelloWorld)fromBytes.fromByte(resultByte);




The others you need to known:

java-cs-bridge serlizes java object's fields. if you dont want a field to be serlized, you can declare the field as transient or declare the @HideToClient attribute before the field. The fields must be java-cs-bridge's supported field.



C#:

code:

HelloWorld hello = new HelloWorld();

//here hello is a object with default constructor.

//the HelloWorld class should declare the attribute JavaClassName with indicate the c# class's corresponding java class.

/*Serlize to binary stream*/

ToByteConvertHelper toBytes = new ToByteConvertHelper();

byte[] resultByte=toBytes.ToByte(source);



/*Deserlize from binary stream*/

FromByteConvertHelper fromBytes = new FromByteConvertHelper();

HelloWorld hello2=(HelloWorld)fromBytes.FromByte(resultByte,0,typeof(HelloWorld));



The others you need to known:

  C#'s API is a little more complex than Java's , at the "fromByte(resultByte,0,typeof(HelloWorld));" ,because the binary stream doesnt contain the C# class info. Adding this feature is very easy but I havnt this requirement now, because java-cs-bridge is design for communicate between Java and C#, not Java and Java or C# and C#.

  Also, java-cs-bridge serlizes c# object's fields. if you dont want a field to be serlized, you can declare the field as NotSerialized or declare the NotJava attribute before the field. The fields must be java-cs-bridge's supported field.

  java-cs-bridge's C# has a special class is JavaObject. If you dont want to write a C# class to map the Java Class, you can use the JavaObject class. the JavaObject contains the information of Java object at runtime. if you dont indicate the expected type when fromByte, it will be the JavaObject as default.



Mapping

Java->C#

Java C#
primitive/primitive wrapper object primitive/primitive wrapper object
List implemention IList implemention(default is ArrayList)
Map implemention IDictionary implemention(default is Hashtable)
Single dim Array Single dim Array
multi dim Array Jagged Array
String String
Date object DateTime object
null null
object object(default is JavaObject)

 C#->Java

C# Java
primitive/primitive wrapper object primitive/primitive wrapper object
IList implemention List implemention(default is ArrayList)
IDictionary implemention Map implemention(default is HashMap)
Single dim Array Single dim Array
multi dim Array Jagged Array
String String
DateTime object Date object
Null null
Object object
JavaObject object

 

Get The Java C# Bridge

downloads

subversion

bug reporting

SourceForge.net Logo Support This Project

RSS

RSS Feed Available