Skip to content

Use contextual lambdas to configure batch artefacts #4818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
fmbenhassine opened this issue Apr 28, 2025 · 6 comments · May be fixed by #4840
Open

Use contextual lambdas to configure batch artefacts #4818

fmbenhassine opened this issue Apr 28, 2025 · 6 comments · May be fixed by #4840

Comments

@fmbenhassine
Copy link
Contributor

This request is about improving the builders of item readers and writers to use Lambdas for configuration options:

Current API:

var reader = new FlatFileItemReaderBuilder()
 .resource(...)
 .delimited()
 .delimiter(",")
 .quoteCharacter('"')
 ...
 .build();

Proposal:

var reader = new FlatFileItemReaderBuilder()
 .resource(...)
 .delimited ( config -> config.delimiter(',').quoteCharcter( '"' ))
 ...
 .build();

cc @joshlong

@kwondh5217
Copy link

Hi @fmbenhassine,

This looks like a great improvement!
I would love to work on this issue. Could you please assign it to me if that's fine?

@fmbenhassine
Copy link
Contributor Author

@kwondh5217 Sure! Thank you for your offer to help!

I believe Spring Security pioneered this configuration approach in the portfolio, so you can take a look there for inspiration.

@kwondh5217
Copy link

Hi @fmbenhassine, thank you for your guidance earlier!

I’d like to clarify the intended direction of the enhancement.

From what I understand, the idea is not just to support lambda-based configuration in FlatFileItemReaderBuilder, but to establish a general DSL-style configuration approach across all ItemReader and ItemWriter builders.

Would you recommend introducing a shared abstraction (e.g. a ConfigurerAwareBuilder base class similar to AbstractConfiguredSecurityBuilder in Spring Security) to support this pattern?

Also, in terms of behavior:

Should we throw an exception when both chaining and lambda styles are used?

Or should we allow overriding?

Or should we allow both and apply in order?

I want to align with the broader design direction before proceeding. Thank you again for your support.

@fmbenhassine
Copy link
Contributor Author

I don't think we need new builders. My initial thinking was about adding new methods to existing builders that accept Consumer<Spec>, similar to the one in SF here: https://github.com/spring-projects/spring-framework/blob/main/spring-beans/src/main/java/org/springframework/beans/factory/BeanRegistry.java#L96

Here is also the original issue in Spring Security: spring-projects/spring-security#5557

So we can imagine new configuration specifications like DelimitedSpec, FixedLengthSpec, etc and use them in current builders.

@kwondh5217
Copy link

Thanks for the detailed guidance @fmbenhassine !
The direction is clear now. I’ll proceed with adding Consumer-based configuration methods to the existing builders using DelimitedSpec and FixedLengthSpec style objects as discussed.

I’ll share a draft PR soon for feedback. Appreciate your support!

@kwondh5217
Copy link

Hi @fmbenhassine,
I’ve submitted a pull request that addresses this issue.
Could you take a look? 🙇‍♂️
Thank you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants