Usage
Overview
To read and write text to and from Java objects, annotate your Java object with instructions on where data is located in the string and how to translate the data into meaningful objects.
Use an instance of FixedFormatManager to load and export the data to and from string representation.
Fixedformat4j requires your Java object to follow these conventions:
- A class to be used with fixedformat4j must be annotated with
@Record. - A property is a pair of a getter and a setter method.
- The getter method is annotated with instructions on how to convert to and from string representation.
Example
The following example defines one string property on a POJO called BasicUsageRecord:
@Record
public class BasicUsageRecord {
private String stringData;
@Field(offset = 1, length = 35)
public String getStringData() {
return stringData;
}
public void setStringData(String stringData) {
this.stringData = stringData;
}
}
FixedFormatManager
An instance of FixedFormatManager translates annotation instructions and controls the actual parsing and formatting.
Fixedformat4j ships with FixedFormatManagerImpl:
FixedFormatManager manager = new FixedFormatManagerImpl();
// load the string into an object representation
BasicUsageRecord record = manager.load(BasicUsageRecord.class, "initial string");
// operate the record in object representation
record.setStringData("some other string");
// export back to string representation
String exportedString = manager.export(record);
// ... do something with the new string
Annotations
Annotations instruct the manager on how to load and export data. See the complete annotations reference.
| Home | Annotations | Nested Records | Examples | Get It |