Skip to Content
avatar image
Former Member

Java mapping for optional fields

Hi experts,

I am doing an java mapping, for the input structure there are some optional optional fields in it. It means while getting input file those fields may or may not contain the value so i what to handle the empty fields because i am getting null pointer exception while reading those fields.

Can any one please suggest how to handle empty fields in java mapping any of your help is highly appreciated.

Regards,

Avinash.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Dec 22, 2014 at 01:08 PM

    Hi Avinash,

    I suggest you to use Temp variables and first Initialize those Variables that you intent to use in your Java Mapping and check it in the code...

    eg:

    String var1 = "";

    var1 = InPutVariable;

    if(var1.equals("")) 

    //do something

    else

    //...

    Regards.

    Azhar

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 22, 2014 at 01:11 PM

    Hi Avniash,

    As it is a Java mapping, you need to take care of error handling yourself. Meaning you need to check in Java source if the variable your trying to read is null or not.

    have fun

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 22, 2014 at 01:21 PM

    Hi Avinash,

    If you are using DOM parser, you can simply check the element content before creating/copying value to target element.

    Consider you have the Node/Element from source message type, check its content or child node is not null.

    There are multiple methods available of the Node class to check this. Refer API

    Eg.

    if(Node.getFirstChild()!=null)

    {

    fullName=Node.getFirstChild().getNodeValue()+" ";

    }

    Thanks,

    Sandip

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 22, 2014 at 05:03 PM

    Avinash,

    As you know, in graphical mapping it can be handle using, if, createif and exits. In Java Mapping, it should be handled using 'if'. Please paste the Java Mapping and error details, here. We can guide you.

    Add comment
    10|10000 characters needed characters exceeded