Hi, I'm trying out the PropertyExtractingDelegatingItemWriter, and I'm seeing that if the arguments are not of the exact types as the targetMethod, then HippyMethodInvoker#findMatchingMethod is called.
When finding candidate arguments, the findMatchingMethod method will populate all fields with the first possible match.
The following is the sample I'm using:
The item being passed has three properties: firstName, lastName, and network. All are Strings. In order to make MyWriter more reusable, I had the doIt(...) method use Object for one of the parameters:Code:<bean id="adaptedItemWriter" class="org.springframework.batch.item.adapter.PropertyExtractingDelegatingItemWriter"> <property name="targetObject" ref="myWriter" /> <property name="targetMethod" value="doIt" /> <property name="fieldsUsedAsTargetMethodArguments"> <list> <value>firstName</value> <value>lastName</value> <value>network</value> </list> </property> </bean> <bean id="myWriter" class="com.mycom.writers.MyWriter"/>
If the "c" argument is a String, then the output is as expected (i.e., firstName, lastName and network are printed out). When "c" is an Object, then HippyMethodInvoker tries to find a method and selects candidate arguments. All three candidate arguments are the first value passed in (i.e., the result is firstName, firstName and firstName printed out).Code:public class MyWriter { public void doIt(String a, String b, Object c) { System.out.println(a + ", " + b + ", and " + c); } }
Any ideas on how to use more generic argument types?


Reply With Quote