Unterminated Double Quotes in Spring Batch

谁都会走 提交于 2019-11-29 12:22:09

if the files have no real quotes (2x quote character) you could go with the solution from the spring forum changing the quote character for the DelimitedLineTokenizer

            <property name="lineTokenizer">
                <bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
                    <property name="quoteCharacter" value="@" />
                </bean>
            </property>
Karura91

I ran into the same problem. However the proposed solution is not an optimal one. What if in your data there isn't a suitable quote character? Unfortunately we don't always have control over input data and pre-processing them is not often a good idea. Exploring the DelimitedLineTokenizer source code I decided to adopt this solution that I will share with this answer. It requires to override a class, but with this we totally remove the quote character issue.

import org.springframework.batch.item.file.transform.DelimitedLineTokenizer;

    public class CustomDelimitedLineTokenizer extends DelimitedLineTokenizer {

        @Override
        protected boolean isQuoteCharacter(char c) {
            return false;
        }

    } 

This way the DelimitedLineTokenizer can't recognize the quote character. Of course if we need this functionality then this solution is not adoptable, however I think it is better than the proposed one that just sort the issue instead of solving it. Hope it will help someone.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!