Java Univocity解析器-如何在已解析的bean中获取行号
使用UnivocityJava Univocity解析器-如何在已解析的bean中获取行号,java,parsing,univocity,Java,Parsing,Univocity,使用UnivocityFixedWidthParser时,如何将记录/行号添加为解析bean中的字段 是否有一个选项可以将bean属性标记为记录号,如: 我使用的是InputValueSwitch。是否有一种方法可以在rowProcessorSwitched()中获取上下文,以便我可以尝试: 在rowProcessorSwitched()中,像 long lineNumber = refToContext.currentLine() - 1; 这是一种有效的方法吗?当解析过程中遇到错误时,它是
FixedWidthParser
时,如何将记录/行号添加为解析bean中的字段
InputValueSwitch
。是否有一种方法可以在rowProcessorSwitched()
中获取上下文,以便我可以尝试:long lineNumber = refToContext.currentLine() - 1;
这是一种有效的方法吗?当解析过程中遇到错误时,它是否可靠
final BeanListProcessor<MyRecord> myProcessor = new BeanListProcessor<MyRecord>(
MyRecord.class);
public void rowProcessorSwitched(RowProcessor from, RowProcessor to) {
ParsingContext context = ... //how to get this?
long lineNumber = context.currentLine(); //if i can get this...
if (from == myProcessor){
(MyRecord)myProcessor.getBeans().get(0).setRecordNumber(lineNumber); //...then this should be possible
//other switch logic
}
}
ParsingContext refToContext = null;
public void processStarted(ParsingContext context) {
refToContext = context;
super.processStarted(context);
}
long lineNumber = refToContext.currentLine() - 1;