Results 1 to 3 of 3

Thread: BeanWrapperFieldSetMapper and using a property specific custom editor?

  1. #1
    Join Date
    Jun 2009
    Posts
    18

    Default BeanWrapperFieldSetMapper and using a property specific custom editor?

    How do I register a custom editor with just a specific bean property. See the config below for the Trade object. e.g. Trade.totalAmount

    I want only the Trade.totalAmount property to use the custom editor (ImpliedScaleBigDecimalEditor) and the other properties to use the Spring default.

    What is the best way to do this (assuming it's possible) ?

    <bean id="tradeFieldSetMapper"
    class="org.springframework.batch.item.file.mapping .BeanWrapperFieldSetMapper">
    <property name="prototypeBeanName" value="trade" />
    <property name="customEditors">
    <map>
    <entry key="java.math.BigDecimal">
    <bean class="com.test.utils.propertyeditor.ImpliedScaleB igDecimalEditor" />
    </entry>
    </map>
    </property>
    </bean>

    <bean id="trade" class="com.test.beans.Trade"
    scope="prototype" />


    Thanks in advance!

    Bob

  2. #2
    Join Date
    Feb 2008
    Posts
    488

    Default

    If you have very specific concerns for the FieldSetMapper, you can always just write a custom mapper instead of trying to work within the BeanWrapperFieldSetMapper.
    For example:
    Code:
      protected static class PlayerFieldSetMapper implements FieldSetMapper<Player> {
        public Player mapFieldSet(FieldSet fieldSet) {
          Player player = new Player();
    
          player.setID(fieldSet.readString(0));
          player.setLastName(fieldSet.readString(1));
          ...
    
          return player;
        }
      }

  3. #3
    Join Date
    Jun 2009
    Posts
    18

    Default additional follow-up for Custom PropertyEditor

    If I did write a custom FieldSetMapper for the Trade bean then that I would NOT config/use the custom Property Editor, correct? If so, that is an option, but I was looking for more of an elegant configuration option where I can set a custom property editor on a specific bean property. It appears that this is possible at some level by looking at the PropertyEditorRegistrySupport.registerCustomEditor (Class requiredType, String propertyPath, PropertyEditor propertyEditor)

    Just need to figure out to get that wired I guess, if possible.

Posting Permissions

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