Fixefid is a Java library for working with flat fixed formatted text files and CSV files.
A lot of improvements has been carried out:
Validation: now it’s possibile to obtain the validation info of all fields. That’s simplify the error management. For instance, if something goes wrong during the processing of the input string, no exception is thrown, and it’s possibile to obtain the validation error info of all fields.
Annotation: all configurations can be managed with annotations. The extended properties style has been maintained but only for advanced configuration, like call back needs.
Valid values accepted list in field annotation
Enum style: it’s been deprecated and not longer supported
Howto avoid substring approach to deal with fixed fields formatted text records. The solution is the Java library Fixefid
Often we have to develop Java methods to deal with fixed fields formatted text records. The format is often used nowadays yet to files transfer between mainframe and unix machines. Almost always the approach is using substring like this:
But that is an error prone pattern. The records are length thousands of chars with many many fields and make a mistake with the offset is not so rarely. And moreover when you have to format the fields to create the record, you have to deal with string right padding, zero lead numeric left padding, boolean format, date format, decimal format, decimal separator, etc etc…
The solution is using a Java library like Fixefid, wich permits to start from a specification in excel, model the record with Java Bean or Java Enum and deal with fields by getter, setter and toString Java methods.
I’ve made a video tutorial where I explain in the detail way the process to start from an excel like this:
to create a Java Bean model like this:
to obtain a records txt file like this:
In this way we can using the standard java bean development to deal with fixed fields formatted text files.
For example you can create a Java Bean like this:
@FixefidRecord(recordLen = 600)
public class Student extends Person {
@FixefidField(fieldLen = 10, fieldOrdinal = 8, fieldType = FieldType.N,
fieldMandatory = FieldMandatory.INOUT)
private Long studentId;
….
}