camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Narsi Nallamilli <narsi.nallami...@gmail.com>
Subject Camel dozer component unable to map custom function on field with null value
Date Wed, 09 Mar 2016 15:51:57 GMT
I am working on a camel project and user camel dozer for transformation(json
to json). However if source json's field is null it is not getting mapped to
targer json's field. So I though to map the field with custom function to
check if the field is null, if so return "null" value to map.

<field custom-converter-id="_customMapping"
custom-converter-param="com.integration.transformation.GetVendorsTransformationUtil,caseNull">
             phone 
            *phone*
</field>

caseNull function,
public Object caseNull(Object object){
	return null==object?"null":object;
}

I have found the issue in 
https://github.com/apache/camel/blob/master/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/CustomMapper.java

In Object mapCustom(Object source) it is calling getClass() on the field
value and in this case being null, throwing Failed to load custom function.

try {
            Class<?> customClass = resolver.resolveClass(className);
            customObj = customClass.newInstance();

            // If a specific mapping operation has been supplied use that
            if (operation != null && prmTypesAndValues != null) {
                method = selectMethod(customClass, operation, source,
prmTypesAndValues);
            } else if (operation != null) {
                method = customClass.getMethod(operation,
source.getClass());
            } else {
                method = selectMethod(customClass, source);
            }
        } catch (Exception e) {
            throw new RuntimeException("Failed to load custom function", e);
        }

Please help with solution.



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-dozer-component-unable-to-map-custom-function-on-field-with-null-value-tp5778801.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message