ENHANCEMENTS
- Added methods to the parser that return Iterable<String[]> or Iterable(https://github.com/uniVocity/univocity-parsers/issues/151)
Rows can now be iterated like this:
for (String[] row : parser.iterate(input, "UTF-8")) {
//do stuff
}
And records:
for (Record row : parser.iterateRecords(new FileInputStream(input), "UTF-8")) {
//do stuff
}
- Support multiple header names in
field
attribute of @Parsed
annotation (https://github.com/uniVocity/univocity-parsers/issues/150)
You can now use the same POJO to parse different files with different headers.
- Adding a
HeaderTransformer
to the @Nested
annotation (https://github.com/uniVocity/univocity-parsers/issues/159)
This allows one to nest the same class inside a parent multiple times, by changing the names assigned to the nested properties. Example for a car with 4 wheels:
public static class Wheel {
@Parsed
String brand;
@Parsed
int miles;
}
public static class Car {
@Nested
Wheel frontLeft;
@Nested
Wheel frontRight;
@Nested
Wheel rearLeft;
@Nested
Wheel rearRight;
}
To parse an input with organized like this: frontLeftWheelBrand,frontLeftWheelMiles,frontRightWheelBrand,frontRightWheelMiles,rearLeftWheelBrand,rearLeftWheelMiles,rearRightWheelBrand,rearRightWheelMiles
, we need to apply a transformation to the property names of each Wheel
instance. This can be done with something like this:
public static class NameTransformer extends HeaderTransformer {
private String prefix;
public NameTransformer(String... args) {
prefix = args[0];
}
@Override
public String transformName(Field field, String name) {
return prefix + Character.toUpperCase(name.charAt(0)) + name.substring(1);
}
}
Now we can change the Nested
annotations to be:
public static class Car {
@Nested(headerTransformer = NameTransformer.class, args = "frontLeftWheel")
Wheel frontLeft;
@Nested(headerTransformer = NameTransformer.class, args = "frontRightWheel")
Wheel frontRight;
@Nested(headerTransformer = NameTransformer.class, args = "rearLeftWheel")
Wheel rearLeft;
@Nested(headerTransformer = NameTransformer.class, args = "rearRightWheel")
Wheel rearRight;
}
And parse the input with:
List<Car> cars = new CsvRoutines(settings).parseAll(Car.class, input);
- added support for annotations in methods (https://github.com/uniVocity/univocity-parsers/issues/160)
@Parsed
or @Nested
annotations now work on individual methods. Modifying the Car
example above to use a List<Wheel>
, one can do the followng:
public static class Car {
List<Wheel> wheels = new ArrayList<Wheel>();
@Nested(headerTransformer = NameTransformer.class, args = "frontLeftWheel")
private void setWheel1(Wheel wheel) { //bad method name created on purpose. Also private.
wheels.add(wheel);
}
@Nested(headerTransformer = NameTransformer.class, args = "frontRightWheel")
private void setWheel2(Wheel wheel) { //bad method name created on purpose. Also private.
wheels.add(wheel);
}
@Nested(headerTransformer = NameTransformer.class, args = "rearLeftWheel")
private void setWheel3(Wheel wheel) { //bad method name created on purpose. Also private.
wheels.add(wheel);
}
@Nested(headerTransformer = NameTransformer.class, args = "rearRightWheel")
private void setWheel4(Wheel wheel) { //bad method name created on purpose. Also private.
wheels.add(wheel);
}
}
-
added support and automatic handling of files with a BOM marker (https://github.com/uniVocity/univocity-parsers/issues/154)
-
Introduced properties from
and to
to the @FixedWidth
annotation, along with FixedWidthFields.addField(int startPosition, int endPosition)
to allow declaring field ranges instead of fixed lengths (https://github.com/uniVocity/univocity-parsers/issues/166)
-
enabled column reordering in CSV, TSV and Fixed-Width writers. This allows users to select which columns of their input should be written and prevents generating empty columns. Just use selectFields
with setColumnReorderingEnabled(true)
(https://github.com/uniVocity/univocity-parsers/issues/167)
-
added a keepResourcesOpen
property in CsvRoutines, TsvRoutines and FixedWidthRoutines to control whether or not to close the Writer
after writing data to the output. Also controls whether the ResultSet
will closed when dumping data from it. (https://github.com/uniVocity/univocity-parsers/issues/172)
BUGS FIXED
-
CSV format auto-detection thrown off by seemingly regular CSV (https://github.com/uniVocity/univocity-parsers/issues/161)
-
Can't provide custom headers when dumping a ResultSet (https://github.com/uniVocity/univocity-parsers/issues/157)
-
ParsingContext.currentParsedContent returns null when input is single length string (https://github.com/uniVocity/univocity-parsers/issues/165)
-
NullValue and EmptyValue are both applied (https://github.com/uniVocity/univocity-parsers/issues/158)
-
NumberFormatException when using record.getDate("field")
in a concurrent environment (https://github.com/uniVocity/univocity-parsers/issues/156)
-
AutomaticConfiguration does not work with MultiBeanListProcessor (https://github.com/uniVocity/univocity-parsers/issues/149)
Source code(tar.gz)
Source code(zip)