java SuperSV无法找到方法异常
我有下面的实现
csvReader = new CsvBeanReader(new InputStreamReader(stream), CsvPreference.STANDARD_PREFERENCE);
lastReadIdentity = (T) csvReader.read(Packages.class, Packages.COLS);
在我的包裹里。阶级
我已经设置了unitcount变量
public String getUnitCount() {
return unitCount;
}
public void setUnitCount(String unitCount) {
this.unitCount = unitCount;
}
当它被当作字符串时,它工作得很好,但是当它被当作整数时,它抛出下面的异常。请帮忙
private int unitCount;
public int getUnitCount() {
return unitCount;
}
public void setUnitCount(int unitCount) {
this.unitCount = unitCount;
}
例外情况:
org.supercsv.exception.SuperCsvReflectionException: unable to find method setUnitCount(java.lang.String) in class com.directv.sms.data.SubscriberPackages - check that the corresponding nameMapping element matches the field name in the bean, and the cell processor returns a type compatible with the field
context=null
at org.supercsv.util.ReflectionUtils.findSetter(ReflectionUtils.java:139)
at org.supercsv.util.MethodCache.getSetMethod(MethodCache.java:95)
# 1 楼答案
我不确定SuperCsv,但是univocity-parsers应该能够顺利地处理这个问题,更不用说它至少比解析输入快3倍
只需为您的类添加注释:
要将CSV解析为bean,请执行以下操作:
披露:我是这个图书馆的作者。它是开源和免费的(Apache V2.0许可证)