Data types mapping
Overview
Data types are one of the main issues when it comes to interoperability between different programming languages. There must be an agreed mapping between the data types in the programming language X and the data types in the programming language Y. A mapping table with the different data types supported is used to accomplish this aspect in WOX with the programming languages it supports at the moment (Java and C#).
The mapping table
The following table shows the data type mapping used in WOX with the Java, and C# programming languages. The first column has the data types used in WOX, and the second and third columns represent the corresponding data types in Java and C#, respectively.
WOX | Java | C# |
---|---|---|
byte | byte/java.lang.Byte | sbyte (System.SByte) |
short | short/java.lang.Short | short (System.Int16) |
int | int/java.lang.Integer | int (System.Int32) |
long | long/java.lang.Long | long (System.Int64) |
float | float/java.lang.Float | float (System.Single) |
double | double/java.lang.Double | double (System.Double) |
char | char/java.lang.Character | char (System.Char) |
boolean | boolean/java.lang.Boolean | bool (System.Bool) |
string | java.lang.String | string (System.String) |
object | java.lang.Object | object (System.Object) |
array | any Array | any Array |
list | java.util.ArrayList | System.Collections.ArrayList |
map | java.util.HashMap | System.Collections.Hashtable |
class | java.lang.Class | System.Type |
The WOX serializer produces the same XML object representation for any object, provided that its fields are only the built-in Java and C# data types listed in the mapping table above, or any user-defined classes which use those data types. This also includes the list and map data types from the collection APIs of both programming languages.
On the other hand, the WOX de-serializer puts a serialized object into a live object in the desired programming language.
Example
According to the mapping table above, some equivalent user-defined classes are presented below. There are more examples of equivalent classes in each section of the Documentation. Two Java classes are shown first, and some equivalent classes in C# next.
//Java classes public class Student { private String name; private int registrationNumber; private Course[] courses; //constructors and methods omitted } public class Course { private int code; private String name; private int term; //constructors and methods omitted }
//C# classes public class Student { private String name; private Int32 registrationNumber; private Course[] courses; //constructors and methods omitted } public class Course { private Int32 code; private String name; private Int32 term; //constructors and methods omitted }