-
Couldn't load subscription status.
- Fork 2.4k
Add MappingItemWriter
#4890
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
Add MappingItemWriter
#4890
Conversation
7e9ea88 to
0870af5
Compare
|
@fmbenhassine this is now ready for review. See #4735 (comment) on why I didn't add the same to |
0870af5 to
437ea68
Compare
768897f to
6859951
Compare
|
Hi @scordio , this is interesting! Thank you for the feature request and the PR! Since this is a specific use case, I don't think adding the method to the item writer interface is the best option. I see this as a very similar to the What about adding a Let me know what you think about that. |
I think in my use case it would just be a This could still be combined with a @Bean
ItemWriter<Person> personItemWriter() {
return new CompositeItemWriter<>(List.of(
new MappingItemWriter(Person::name, nameItemWriter), // ItemWriter<String>
new MappingItemWriter(Person::age, ageItemWriter), // ItemWriter<Integer>
new PersonAddressItemWriter() // ItemWriter<Person>
));
}In this example, it's still possible to use an Or did you imagine something different? I suppose when this feature goes to a dedicated class, there won't be any Summarizing, if you agree, I'd create a |
That's right. The mapping function would be passed to the This won't be a breaking change, so we still have time to include in v6. Looking forward to your update on this. Thanks again for everything you do for Spring Batch! 🙏 |
6859951 to
7db407e
Compare
7db407e to
1bd5627
Compare
...e/src/main/java/org/springframework/batch/infrastructure/item/support/MappingItemWriter.java
Show resolved
Hide resolved
Signed-off-by: Stefano Cordio <[email protected]>
1bd5627 to
020d492
Compare
|
Thank you for the updates! Rebased and merged as 2621b20. I realise that this new item writer allows for a kind of "deconstruction pattern" where a big item can be deconstructed into smaller parts (thanks to the mapping function, and the tests are great examples) where each part is written to a different location. This is awesome! |
|
@fmbenhassine thanks for merging it! I realized only now that this might deserve an entry in the user guide. If you agree, I would raise another small PR for it. |
|
I was planning to update that as part of the big documentation overhaul for v6, but if you want to open a PR you are welcome! |
|
Sure, I can take care of it 🙂 |
|
I reviewed my use cases to reconfirm these changes would integrate correctly and I realized one more detail a bit late, sorry about it 🙁 There is one case where the existing writer is an @fmbenhassine do you have any concerns with this? If not, I'd be happy to raise a PR for it (combined with the docs updates). |
|
State management is not mandatory, we have some decorators that are not restartable. But if you can make this mapping writer an item stream, then yes that would be great! |
|
Oh, you beat me to it 😄 I just raised #5046, I'll rebase it soon and align it with your changes. |
ItemWriterwithCompositeItemWriterexpecting different item types #4735