SuperCSV CSV出力処理時ParseBoolでエラー
先程のParseDateでエラー(http://d.hatena.ne.jp/kurukuru-papa/20100119/1263908940)と同様に、ParseBoolを使用した時もClassCastExceptionが発生しました。
そのため、次のようなクラスを作成し、ParseBoolの替りに使用すると解決しました。
import org.supercsv.cellprocessor.ParseBool; import org.supercsv.exception.NullInputException; import org.supercsv.exception.SuperCSVException; import org.supercsv.util.CSVContext; public class ParseBoolEx extends ParseBool { public ParseBoolEx() { super(); } @Override public Object execute(final Object value, final CSVContext context) throws SuperCSVException { if (value == null) { throw new NullInputException("Input cannot be null on line " + context.lineNumber + " column " + context.columnNumber, context, this); } Object result; if (value instanceof String) { // read時 result = new Boolean((String) value); } else if (value instanceof Boolean) { // write時 result = ((Boolean) value).toString(); } else { throw new SuperCSVException("Cannot parse \"" + value + "\" to a boolean on line " + context.lineNumber + " column " + context.columnNumber, context, this); } return result; } }
動作環境
- OS : Windows 7
- SuperCSV : Version 1.52