-
Sep 16th, 2011, 12:26 PM
#1
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
-
Sep 17th, 2011, 09:59 AM
#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.
-
Sep 17th, 2011, 01:06 PM
#3
I am using Pattern Matching Composite line mapper.
Thanks
Shravan
-
Sep 18th, 2011, 11:54 AM
#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
-
Sep 19th, 2011, 02:40 AM
#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" />
-
Sep 19th, 2011, 03:41 AM
#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 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
-
Forum Rules