You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Providing an array of the field names of a domain class is very common in Spring projects, such as Spring Batch when configuring reading or writing of flat-files (CSV, FWV). Using the Lombok@FieldNameConstants(asEnum=true) annotation makes it easier. However, the last step is still somewhat clumsy: @FieldNameConstants(asEnum=true) class MyDomainClass {...} var names = Stream.of(MyDomainClass.Fields.values()).map(Enum::name).toArray(String[]::new);
So, my suggestion is to add the annotation property asArray, which would generate a static final String[] with the names.
With Lombok
@FieldNameConstants(asArray=true)
@OtherLombokAnnotations
class Account {
private String accno;
private long balance;
}
With Java
class Account {
private String accno;
private long balance;
public static final String[] Fields = {"accno", "balance"};
//. . .
}
As an example, with the suggested property it would be a breeze to configure an CSV ItemWriter in Spring Batch:
@Bean
public FlatFileItemWriter<Account> itemWriter(Resource file) throws Exception {
return new FlatFileItemWriterBuilder<Account>()
.name("Account")
.resource(file)
.delimited()
.names(Account.Fields) // <----here
.build();
}
The text was updated successfully, but these errors were encountered:
Providing an array of the field names of a domain class is very common in Spring projects, such as Spring Batch when configuring reading or writing of flat-files (CSV, FWV). Using the Lombok
@FieldNameConstants(asEnum=true)
annotation makes it easier. However, the last step is still somewhat clumsy:@FieldNameConstants(asEnum=true) class MyDomainClass {...}
var names = Stream.of(MyDomainClass.Fields.values()).map(Enum::name).toArray(String[]::new);
So, my suggestion is to add the annotation property
asArray
, which would generate astatic final String[]
with the names.With Lombok
With Java
As an example, with the suggested property it would be a breeze to configure an CSV ItemWriter in Spring Batch:
The text was updated successfully, but these errors were encountered: