getting field names of null values of an input document

Hello, I wish to obtain the all the fields of a document input, including fields that have a value of null.

Currently, given a document input, when I loop through it in a java service like

IData doc = IDataUtil.getIData(pipeline.getCursor(), “doc”); // service take as input a document doc
IDataCursor cursor = doc.getCursor();
while (cursor.next()) {
String key = cursor.getKey();
Object value = cursor.getValue();

// do things with key and value
}

The field key names of the fields with null values are gone. However, I still need the names of the field keys, even if the values is null. The input document can have any number of fields. What would be a good way to fix this problem? Thank you.

Is your input document going to be flat? If it is not then you will have to code for all things that can be in a document. Below is some rudimentary code for you to begin with, you can modify this code to manipulate IData.

Try adding the IData to the same code below and that should handle everything that can come in a IData document. I am leaving that to you to figure it out.


IDataCursor pipelineCursor = pipeline.getCursor();		
IData	inputDoc = IDataUtil.getIData( pipelineCursor, "inputDoc" );
if ( inputDoc != null)
	{
		//Create a dynamic output array to store the key\value pairs from the document.
		ArrayList<IData> outputDocarr = new ArrayList<IData>();		
		ArrayList<String> temp=new ArrayList<String>();
				
		IDataCursor idc=inputDoc.getCursor();
		IData output=null;
		IDataCursor idcOut=null;
						
		while(idc.next()){
			output= IDataFactory.create();
			idcOut= output.getCursor();
					
			// Add to the output doc array only if the cursor has a string or object key\value pair.				
			if ((idc.getValue() instanceof String) ||((idc.getValue() instanceof Object))){
				IDataUtil.put(idcOut, "key", idc.getKey());
				IDataUtil.put(idcOut, "value", idc.getValue());
				idcOut.destroy();
				outputDocarr.add(output);
			}
			else if(idc.getValue() instanceof IData){
				idc.next();
			}
			//value is empty
			else if(idc.getValue()==null){
				temp.add(idc.getKey());
				IDataUtil.put(idcOut, "key", idc.getKey());
				IDataUtil.put(idcOut, "value", null);
				outputDocarr.add(output);
			}
		}
		IDataUtil.put( pipelineCursor, "outputDocList", outputDocarr.toArray(new IData[outputDocarr.size()]));
		IDataUtil.put(pipelineCursor, "test", temp.toArray(new String[temp.size()]));
	}			
pipelineCursor.destroy();