-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Kotlin data class support for FlatFileItemReaderBuilder
#4568
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
Comments
Thank you for the suggestion.
Is there a reliable way to detect that? My concern with this request is that it would introduce code that is specific to Kotlin data classes (and possibly other JVM languages in the future if we get similar requests). As you mentioned, |
You makes sense. But when both
My first idea was that using Optional Kotlin dependency would not affect users who don't use Kotlin. Or we'd be better to introduce a if (this.targetType != null || StringUtils.hasText(this.prototypeBeanName)) {
// this.fieldSetMapperFactories contains BeanWrapperFieldSetMapper and RecordFieldSetMapper by default
for (FieldSetMapperFactory factory : this.fieldSetMapperFactories) {
if (factory.canMap(this.targetType) {
lineMapper.setFieldSetMapper(factory.create(this.targetType);
break;
}
}
} |
I've filled an issue to spring-framework about providing a way to detect a Kotlin data class. |
I have decline the Framework issue created, and would advise to use |
Thank you for the updates, @0x1306e6d ! Based on @sdeleuze feedback, I would keep this type detection and mapper decision on the user's side rather than the framework side. Thank you both for the follow-up on this. Appreciated your time! |
Please do a quick search on Github issues first, the feature you are about to request might have already been requested.
Expected Behavior
Make
FlatFileItemReaderBuilder
detect whether the target type is Kotlin data class and sets properFieldSetMapper
which is notBeanWrapperFieldSetMapper
.RecordFieldSetMapper
works with a Kotlin data class but we might be better to introduce a new dedicatedFieldSetMapper
.Current Behavior
The
FlatFileItemReaderBuilder
only detects whether the target type is record or not. So it sets theBeanWrapperFieldSetMapper
which instantiates the target type by the default constructor (no-args) and causesNotWritablePropertyException
:spring-batch/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/builder/FlatFileItemReaderBuilder.java
Lines 463 to 467 in d1bd771
Context
As a workaround, we might make the data class fields nullable and mutable like:
but as you know, it doesn't leverage the Kotlin's features.
The text was updated successfully, but these errors were encountered: