Results 1 to 2 of 2

Thread: HippyMethodInvoker too relaxed?

  1. #1

    Default HippyMethodInvoker too relaxed?

    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:

    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"/>
    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:
    public class MyWriter {
    	public void doIt(String a, String b, Object c) {
    		System.out.println(a + ", " + b + ", and " + c); 
    	}
    }
    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).

    Any ideas on how to use more generic argument types?

  2. #2
    Join Date
    Jun 2005
    Posts
    4,232

    Default

    You could raise a JIRA ticket to get this looked at in more detail. For now I suspect you will have to write your own delegating writer and use a less subtle approach to calling your specific method.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •