Nested Record sample doesnt work
com.ancientprogramming.fixedformat4j.exception.FixedFormatException: com.ancientprogramming.fixedformat4j.format.impl.ByTypeFormatter cannot handle datatype[com.foo.exampleRecord]. Provide your own custom FixedFormatter for this datatype.
@StevenGerdes got the same issue here. As a workaround, I implemented the FixedFormatter on every possible sub-record, eg.:
In my parent record:
@Field(offset = 31, length = 100, formatter = SubRecord.class) public SubRecord getSubRecord() { .. }
In my sub record: ` @Record(length = 100) public class SubRecord implements FixedFormatter {
String a = "foo";
String b = "bar";
@Field(offset = 1, length = 40)
public String getA() {
return a;
}
@Field(offset = 41, length = 60)
public String getB() {
return b;
}
@Override
public Object parse(String s, FormatInstructions formatInstructions) throws FixedFormatException {
return null;
}
@Override
public String format(Object o, FormatInstructions formatInstructions) throws FixedFormatException {
FixedFormatManager manager = new FixedFormatManagerImpl();
return manager.export(this);
}
}`
@StevenGerdes .. and encapsulated it in an abstract super class:
`public abstract class AbstractSubRecordFixedFormatter implements FixedFormatter {
@Override
public Object parse(String s, FormatInstructions formatInstructions) throws FixedFormatException {
return null;
}
@Override
public String format(Object o, FormatInstructions formatInstructions) throws FixedFormatException {
FixedFormatManager manager = new FixedFormatManagerImpl();
return manager.export(this);
}
}`
which now is the base class for all my records
Apparently there were still some more problems. However, I found out the maven repo only hosts up to version 1.2.2. If you download the source code and build it yourself, you will get version 1.4.0-SNAPSHOT, which is working fine.
@davidcyp
Please check my work on https://github.com/ty-vincenthung/fixedformatter4j/tree/1.0-snapshot
it is based on version 1.2.2 and all nested need to be defined @Record and @Field
Thanks @ty-vincenthung I'll do asap. Not working on the project anymore so need to do some setup but really thanks for the answer.
I have updated the formatter which support Generic Object, List and Enum