fixedlength icon indicating copy to clipboard operation
fixedlength copied to clipboard

Support for Java 14 Records

Open mbechto opened this issue 1 year ago • 1 comments

It would be nice to be able to use this library with Java 14 records, for example:

public record LineRecord(
    @FixedField(offset = 1, length = 42)
    String firstStr,
    @FixedField(offset = 43, length = 5)
    String secondStr
) {}

As it is a lot more declarative than defining traditional POJOs & it automatically implements toString, hashCode and equals.

mbechto avatar May 16 '24 13:05 mbechto

Maybe an alternative approach could be to add some support for Immutables. This would more or less have the same benefits while maintaining compatibility with Java 8 (Immutables is Java 8).

So far, I tried to create an interface and annotate it like:

// create DTO with setters
@Value.Modifiable
interface LineRecord {
    @FixedField(offset = 1, length = 42)
    String firstStr();
    @FixedField(offset = 43, length = 5)
    String secondStr();
}

Problem here being, that methods cannot be annotated with @FixedField.

mbechto avatar May 16 '24 13:05 mbechto

Hey, @mbechto , it took a little more time to implement it :) anyway, check out the 0.12 version, there is an experimental support of records. I'll close this issue, if you will face some problems using records, please open new issues here.

Thank you for great enhancement proposal!

g0ddest avatar Oct 13 '24 11:10 g0ddest