user109447
user109447

Reputation: 1129

Spring batch: handle subclasses

Lets suppose that I have class Event with and 10 subclasses (SubEvent1, SubEvent2... and so on) of class Event. I have configured for spring batch ItemReader, ItemProcessor and ItemWriter.

My item processor looks like:

ItemProcessor<Event, Outputclass> {
 OutputClass process(Event e) {
   if(e instancof SubEvent1) {
     return processSubEvent1(e);
   } else if(e instanceof SubEvent2) {
     return processSubEvent2(e);
   } else ...
}

is it possible to avoid those instanceof and process it by class specific Processors?

Upvotes: 1

Views: 233

Answers (1)

Mahmoud Ben Hassine
Mahmoud Ben Hassine

Reputation: 31720

You should be able to do that using a combination of:

Hope this helps.

Upvotes: 1

Related Questions