The write method of Itemwriter has been changed in the spring version 5.
@Override
public void write(List<? extends List<DataDTO>> items) throws Exception{
for(List<DataDTO> sublist:items){
writer.write(sublist);
}
The above writer is FlatFileItemWriter.
I changed to the following
@Override
public void write(Chunk<? extends List<DataDTO>> items) throws Exception{
for(List<DataDTO> sublist:items){
writer.write((Chunk<? extends DataDTO>)sublist);
}
}
Is this correct way of replacing/fix? need some help.
Im expecting the correct fix.
Expecting coreect replacement.
According to the Spring Batch 5.0 migration guide, most references to Lists in the API were replaced with Chunk.
- The signature of the method
ItemWriter#write(List)was changed toItemWriter#write(Chunk)- All implementations of
ItemWriterwere updated to use theChunkAPI instead ofList- All methods in the
ItemWriteListenerinterface were updated to use theChunkAPI instead ofList- All implementations of
ItemWriteListenerwere updated to use theChunkAPI instead ofList- The constructor of
ChunkRequestwas changed to accept aChunkinstead of aCollectionof items- The return type of
ChunkRequest#getItems()was changed fromListtoChunk
A good way to do the migration in your code is to use one of Chunk's constructors.
Example:
@Override
public void write(Chunk<? extends List<DataDTO>> items) throws Exception{
for(List<DataDTO> sublist:items){
writer.write(new Chunk<>(sublist));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With