Home Help Center

Handling of Nulls for ICE datatypes

dilbaghdilbagh Member Dilbagh DhindsaOrganization: CitiProject: Repository of various financial securities
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

  • mesmes CaliforniaAdministrators, ZeroC Staff Mark SpruiellOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    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
Sign In or Register to comment.