Summary: This page is focused on designing interoperable classes manually, and some related advanced features.
For more information about the code generation tool, see the gs.xml Code Generator. The .NET-Java example demonstrates many .NET-Java interoperability features. For more details, see GigaSpaces Starter Examples; .NET; DotNetJava *** Designing Interoperable Classes
C# |
Java |
Using GigaSpaces.Core.Metadata;
namespace MyCompany.MyProject.Entities
{
[SpaceClass(AliasName="com.mycompany.myproject.entities.Person")]
public class Person
{
private string _name;
[SpaceProperty(AliasName="name")]
public string Name
{
get { return this._name; }
set { this._name = value; }
}
}
}
|
package com.mycompany.myproject.entities;
public class Person
{
private String name;
public String getName()
{
return this.name;
}
public void setName(String name)
{
this.name = name;
}
}
|
Guidelines and Restrictions The following guidelines and restrictions should be followed in order to enable platform interoperability:
- The full class name (including package\namespace) in all platforms should be identical.
Since java packages use a different naming convention than .Net namespaces, it is recommended to use the SpaceClass(AliasName="") feature to map a .Net class to the respective java class.
- The properties/fields stored in the space in all platforms should be identical.
In Java, only properties are serialized into the space. In .NET, both fields and properties are serialized, so you can mix and match them. Since java properties start with a lowercase letter, whereas .Net properties usually start with an uppercase letter, it is recommended to use the SpaceProperty(AliasName="") feature to map a property/field name from .Net to java.
- Only the types listed in the table below are supported. If one of your fields uses a different type, you can use the class only in a homogeneous environment.
Arrays of these types are supported as well. You can also use .NET enumerations, which are treated as their underlying .NET type. Java enums are not supported. If your class contains a field whose type is not in the table, you can use SpaceExclude to exclude it from the space. Some of the types have different charactaristics in .NET and Java (signed\unsigned, nullable\not nullable, precision, etc.) This can lead to runtime exceptions (e.g. trying to store null in a .NET structure) or unexpected results (e.g. copying values between signed and unsigned fields).
Supported Types for Matching and Interoperability The following types are supported by the space for matching and interoperability:
- In .Net a byte is unsigned, whereas in java a byte is signed.
- These types can be either nullable or not nullable in .Net, whereas in java they are always nullable.
- In .Net a DateTime is measured in ticks (=100 nanoseconds) since 1/1/0001, whereas in java a Date is a measured in milliseconds since 1/1/1970.
- The types Decimal (.Net) and BigDecimal (java) have different precision and range (see .Net and java documentation for more details). In addition, be aware that serialization/deserialization of these types is relatively slow, compared to other numeric types. As a rule of thumb these types should not be used, unless the other numeric types presicion/range is not satisfactory.
Arrays and Collections support The following collections are mapped for interoperability:
- In java, the Properties type allows the user to store keys and values which are not strings.
***Link required |