gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 11:39:51 25 4
gpt4 key购买 nike

当我实例化 FixedWidthParser 时与 MultiBeanListProcessor CommonParserSettings#configureFromAnnotations(beanClass)没有被调用,因为它不是 AbstractBeanProcessor 的实例。不应该为每个 AbstractProcessorBean 调用该方法吗?在 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();
}

这是该 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 */
}

异常(exception):

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

PS:如果我更改 MultiBeanListProcessor(FileHeader.class) 就可以了对于BeanListProcessor(FileHeader.class) .

最佳答案

在 2.4.2 版本中修复。 SNAPSHOT 构建已修复此问题,目前可通过 Maven 或直接从 here 获得。 .

希望这有帮助

关于java - Univocity - 自动配置不适用于 MultiBeanListProcessor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42931479/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com