Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Univocity-自动配置不适用于MultiBeanListProcessor_Java_Univocity - Fatal编程技术网

Java Univocity-自动配置不适用于MultiBeanListProcessor

Java Univocity-自动配置不适用于MultiBeanListProcessor,java,univocity,Java,Univocity,当我使用MultiBeanListProcessor实例化FixedWidthParser时,不会调用CommonParserSettings\configureFromAnnotations(beanClass),因为它不是AbstractBeanProcessor的实例。是否应该为MultiBeanListProcessor中的每个AbstractProcessorBean调用该方法 示例代码: FixedWidthParserSettings settings = new FixedWid

当我使用
MultiBeanListProcessor
实例化
FixedWidthParser
时,不会调用
CommonParserSettings\configureFromAnnotations(beanClass)
,因为它不是AbstractBeanProcessor的实例。是否应该为
MultiBeanListProcessor
中的每个
AbstractProcessorBean
调用该方法

示例代码:

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();
}
这是bean的缩写版本:

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)
BeanConversionProcessor.mapFieldIndexes
上的
context.headers()
的值为空

有没有其他方法可以使用
多BeanListProcessor
头文件中的
自动配置


注意:如果我将
多BeanListProcessor(FileHeader.class)
多BeanListProcessor(FileHeader.class)
更改为2.4.2版中的固定版本,这就行了。快照构建已经修复了此问题,目前可通过maven或直接从中获得


希望这有助于在2.4.2版中修复。快照构建已经修复了此问题,目前可通过maven或直接从中获得

希望这有帮助