Announcement Announcement Module
Collapse
No announcement yet.
BeanWrapperFieldSetMapper and using a property specific custom editor? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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;
        }
      }

    Comment


    • #3
      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.

      Comment

      Working...
      X