Announcement Announcement Module
Collapse
No announcement yet.
Issue#FlatFileItemReader automatically Trimming the leading and trailing spaces Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Issue#FlatFileItemReader automatically Trimming the leading and trailing spaces

    Hi,

    FlatFileItemReader trims the leading and trailing spaces automaticaly.

    How to restrict it. Please help

    For example if my line in the file is (I am indicating spaces with text space in below example)
    spacespacespaceMyName Is Shravan spacespacespace

    then when i read the line i am getting only "MyName Is Shravan" and leading and trailing spaces have been removed.


    Please help how to prevent this from happening (I want the whole line as is)


    Thanks
    Shravan

  • #2
    Can you post the configuration of your FlatFileItemReader and if it exists the code for a custom lineMapper ?

    When i use the FlatfileItemReader with a PassThroughLineMapper the whitespace is not removed.

    Comment


    • #3
      I am using Pattern Matching Composite line mapper.

      Thanks
      Shravan

      Comment


      • #4
        I tried the PatternMatchingCompositeLineMapper and it does not remove any whitespace, see the simple example in my github repository.

        How is your mapper configured? What tokenizers/fieldSetMappers do you use?

        I can't help you any further without more information

        Comment


        • #5
          Here is my code please help. We are using custom mappers.

          <beans:bean id="prntOnlyFeedFileReader" scope="step"
          class="com.metlife.metcheck.batch.domain.itemreade r.loader.MetcheckFlatFileItemReader">
          <beansroperty name="resource"
          value="#{jobParameters['feedFileName']}" />
          <beansroperty name="lineMapper">
          <beans:bean
          class="org.springframework.batch.item.file.mapping .PatternMatchingCompositeLineMapper" scope="step">
          <beansroperty name="tokenizers">
          <beans:map>
          <beans:entry key="#{jobExecutionContext['BODY_TOKENIZER']}"
          value-ref="prntOnlyBodyTokenizer" />
          <beans:entry key="#{jobExecutionContext['TRAILER_TOKENIZER']}"
          value-ref="prntOnlyTrailerTokenizer" />
          </beans:map>
          </beansroperty>

          <beansroperty name="fieldSetMappers">
          <beans:map>
          <beans:entry key="#{jobExecutionContext['BODY_TOKENIZER']}"
          value-ref="prntOnlyBodyMapper" />
          <beans:entry key="#{jobExecutionContext['BODY_TOKENIZER']}"
          value-ref="commonPrntOnlyFieldSetMapper" />
          <beans:entry key="#{jobExecutionContext['TRAILER_TOKENIZER']}"
          value-ref="prntOnlyTrailerMapper" />
          </beans:map>
          </beansroperty>
          </beans:bean>
          </beansroperty>
          </beans:bean>


          <beans:bean id="commonPrntOnlyFieldSetMapper"
          class="com.metlife.metcheck.batch.domain.mapper.Co mmonPrntOnlyFieldSetMapper">
          <beansroperty name="batchLoaderView" ref="bodyLoaderBean" />
          </beans:bean>

          <beans:bean id="prntOnlyBodyMapper" scope="step"
          class="org.springframework.batch.item.file.mapping .BeanWrapperFieldSetMapper"
          prototypeBeanName="bodyLoaderBean" />


          <beans:bean id="prntOnlyTrailerMapper" scope="step"
          class="org.springframework.batch.item.file.mapping .BeanWrapperFieldSetMapper"
          prototypeBeanName="batch" />

          Comment


          • #6
            please use code tags to make the code readable

            it looks like the problem is the BeanWrapperFieldSetMapper, its mapFieldSet method uses the getProperties method of the underlying FieldSet implementation, if you use the standard DelimitedLineTokenizer you get the DefaultFieldSet and its getProperties implementation trims Strings


            how to change the behaviour ?

            to make it easy you could change the Default... implementations for the factory and fieldset, because the only changed part would be the getProperties method

            Beware: if you have numbers in your dataBeans and the input, the changed behaviour might create undesired problems like numberFormatException or the BeanWrapperFieldSetMapper will be unable to map the data. Maybe you have to create own mapper implementations.
            Last edited by michael.lange; Sep 19th, 2011, 03:54 AM.

            Comment

            Working...
            X