cancel
Showing results for 
Search instead for 
Did you mean: 

Java mapping for optional fields

avinash_ayanala
Participant
0 Kudos

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.

Accepted Solutions (0)

Answers (4)

Answers (4)

RaghuVamseedhar
Active Contributor
0 Kudos

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.

sandip_hole
Participant
0 Kudos

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

Former Member
0 Kudos

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

azharshaikh
Active Contributor
0 Kudos

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