github uniVocity/univocity-parsers v2.5.0
"Massive" minor release with heaps of updates

latest releases: v2.9.1, v2.9.0, v2.8.4...
8 years ago

ENHANCEMENTS

  • Added methods to the parser that return Iterable<String[]> or Iterable(#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 (#150)

You can now use the same POJO to parse different files with different headers.

  • Adding a HeaderTransformer to the @Nested annotation (#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 (#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 (#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 (#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) (#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. (#172)

BUGS FIXED

  • CSV format auto-detection thrown off by seemingly regular CSV (#161)

  • Can't provide custom headers when dumping a ResultSet (#157)

  • ParsingContext.currentParsedContent returns null when input is single length string (#165)

  • NullValue and EmptyValue are both applied (#158)

  • NumberFormatException when using record.getDate("field") in a concurrent environment (#156)

  • AutomaticConfiguration does not work with MultiBeanListProcessor (#149)

Don't miss a new univocity-parsers release

NewReleases is sending notifications on new releases.