2017-03-21 103 views
1

當我實例化一個FixedWidthParserMultiBeanListProcessor時,CommonParserSettings#configureFromAnnotations(beanClass)未被調用,因爲它不是AbstractBeanProcessor的實例。 MultiBeanListProcessor中的每個AbstractProcessorBean都不應該調用該方法嗎?Univocity - 自動配置不適用於MultiBeanListProcessor

的示例代碼:

FixedWidthParserSettings settings = new FixedWidthParserSettings(); 
settings.setAutoConfigurationEnabled(true); 
settings.setHeaderExtractionEnabled(false); 
settings.getFormat().setLineSeparator("\n"); 

MultiBeanListProcessor processor = new MultiBeanListProcessor(FileHeader.class, ...); // FileHeader has an @Headers and fields with @Parsed 
settings.setProcessor(processor); 

FixedWidthParser parser = new FixedWidthParser(settings);  // Here it should call configureFromAnnotations 

try (Reader reader = getReader("/positional-file")) { 

    parser.parse(reader); // the exception is throwed here 

} catch (IOException e) { 
    e.printStackTrace(); 
} 

這是豆的縮寫形式:

import com.univocity.parsers.annotations.FixedWidth; 
import com.univocity.parsers.annotations.Headers; 
import com.univocity.parsers.annotations.Parsed; 
import com.univocity.parsers.fixed.FieldAlignment; 

@Headers(sequence = { "bankCode", "batchCode", "registerType" }, extract = false, write = false) 
public class FileHeader { 

    @Parsed 
    @FixedWidth(value = 3, alignment = FieldAlignment.RIGHT, padding = '0') 
    private Integer bankCode; 

    @Parsed 
    @FixedWidth(value = 4, alignment = FieldAlignment.RIGHT, padding = '0') 
    private Integer batchCode; 

    @Parsed 
    @FixedWidth(value = 1, alignment = FieldAlignment.RIGHT, padding = '0') 
    private Integer registerType;` 

    /** getters and setters */ 
} 

例外:

com.univocity.parsers.common.DataProcessingException: Could not find fields [bankCode, bankName, batchCode] in input. Please enable header extraction in the parser settings in order to match field names. 
Internal state when error was thrown: line=0, column=0, record=1, charIndex=240 
    at com.univocity.parsers.common.processor.core.BeanConversionProcessor.mapFieldIndexes(BeanConversionProcessor.java:360) 
    at com.univocity.parsers.common.processor.core.BeanConversionProcessor.mapValuesToFields(BeanConversionProcessor.java:289) 
    at com.univocity.parsers.common.processor.core.BeanConversionProcessor.createBean(BeanConversionProcessor.java:457) 
    at com.univocity.parsers.common.processor.core.AbstractBeanProcessor.rowProcessed(AbstractBeanProcessor.java:51) 
    at com.univocity.parsers.common.processor.core.AbstractMultiBeanProcessor.rowProcessed(AbstractMultiBeanProcessor.java:101) 
    at com.univocity.parsers.common.Internal.process(Internal.java:21) 
    at com.univocity.parsers.common.AbstractParser.rowProcessed(AbstractParser.java:596) 
    at com.univocity.parsers.common.AbstractParser.parse(AbstractParser.java:132) 

context.headers()BeanConversionProcessor.mapFieldIndexes的值爲空。

是否有任何其他方式使用MultiBeanListProcessorAutoConfiguration@Headers

P.S .:其工作是否將MultiBeanListProcessor(FileHeader.class)更改爲​​。

回答

0

將在2.4.2版中修復。 SNAPSHOT構建已經修復,目前可通過maven或直接從here獲得。

希望這會有幫助

相關問題