I can't speak directly to JSON to JSON mapping as I use Dozer for mapping Java/XML/JSON with POJOs but I've run into a similar problem and the solution may be somewhat similar. Where I've run into it is if there aren't getters/setter pairs on generated objects Dozer will sometimes access a null object and then the game is done. To get around that it has a setting to tell it to use field access for that and it will then create the correct object type for that field and set it.
I don't know if that works in JSON to JSON. On Wed, Mar 9, 2016 at 9:51 AM, Narsi Nallamilli <[email protected] > wrote: > 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. >
