Zed
Zed

Reputation: 5921

Passing a Map to IteratorItemReader

I've been having hard time figuring out how to pass a Map to the Spring's IteratorItemReader

Basically, what I have is this, where I retrieve data from remote API:

Map<Structure, List<Structure>> data = getData();

The problematic part is when I try to pass this data to the IteratorItemReader

deleg = new IteratorItemReader<>(data);

The error that I'm getting is: Cannot infer argument(unable to resolve constructor). Before, I was passing just an ArrayList to IteratorItemReader and it played nice. So, now with a Map I'm not sure what to do as I'm not really experienced with Java. Any help is appreciated. I have really no room for data processing at the place where IteratorIteamReader is invoked, so I need to find a way to just pass it a Map and then later process data in the different part of code.

Upvotes: 1

Views: 322

Answers (2)

Arjit
Arjit

Reputation: 425

Map isn't Iterable but EntrySet is.

Use this-

IteratorItemReader<Entry<Structure, List<Structure>>> deleg = new IteratorItemReader<>(data.entrySet());
System.out.println(deleg.read());

Upvotes: 1

Erik P
Erik P

Reputation: 420

The IteratorItemReader accepts only an argument that implements Iterable. A Map is not Iterable, but for example the entrySet of the Map is.

deleg = new IteratorItemReader<>(data.entrySet());

Upvotes: 1

Related Questions