Archived

This forum has been archived. Please start a new discussion on GitHub.

Handling of Nulls for ICE datatypes

We are using ICE with JAVA application which can have null values for Object attributes as an example below:

Class A{

Long along=null;
Boolean abool=null;

}
Now What is the best way to handle these nulls in ICE data types as we just have primitive types in ICE?

Comments

  • mes
    mes California
    Welcome to the forum!

    Like in Java, you'll need to use a "wrapper" class to provide null semantics for primitive types. For example:
    // Slice
    class Boolean
    {
        bool val;
    };
    
    class A
    {
        Boolean b;
    };
    
    The disadvantage of using wrapper classes is that non-null values consume more space in Ice protocol messages than the primitive types do. Of course, whether this increase is actually important depends on the requirements of your application. If minimizing message size is critical, another approach is to use sequences:
    sequence<bool> Boolean;
    
    class A
    {
        Boolean b;
    };
    
    In this case, an empty sequence represents the null value, otherwise the sequence contains one element. Naturally, this design is much less obvious and therefore is more likely to be misunderstood and misused.

    Hope that helps,
    Mark