Results 1 to 6 of 6

Thread: Issue#FlatFileItemReader automatically Trimming the leading and trailing spaces

  1. #1

    Default 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. #2

    Default

    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.

  3. #3

    Default

    I am using Pattern Matching Composite line mapper.

    Thanks
    Shravan

  4. #4

    Default

    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

  5. #5

    Default

    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" />

  6. #6

    Default

    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 at 03:54 AM.

Posting Permissions

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