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 List
s in the API were replaced with Chunk
.
- The signature of the method
ItemWriter#write(List)
was changed toItemWriter#write(Chunk)
- All implementations of
ItemWriter
were updated to use theChunk
API instead ofList
- All methods in the
ItemWriteListener
interface were updated to use theChunk
API instead ofList
- All implementations of
ItemWriteListener
were updated to use theChunk
API instead ofList
- The constructor of
ChunkRequest
was changed to accept aChunk
instead of aCollection
of items- The return type of
ChunkRequest#getItems()
was changed fromList
toChunk
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));
}
}