Announcement Announcement Module
No announcement yet.
how to store permutations of an item Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to store permutations of an item

    I am quite new to Spring Batch and encountered a problem for which I cannot see an elegant way to solve, maybe someone here has a hint for me.

    Her comes the brief description of what I try to accomplish:

    I try to read data from different XML sources an write them to a common output format.

    As reader I use StaxEventItemReader and the according Jaxb Models.
    In the Processors I Map the different Object Models to the common one.
    The writer simply writes stuff to csv or database.

    The problem is, that an XML can look something like that (extremely simplified to show the problem):

    Which leads to items of type "xmlitem" with a member of type "List<name>" and a member "param1" when unmarshalling on "xmlitem".

    When writing this item I want to have two entries in the output as follows:

    out1: commonParam=blah, commonName=name1
    out2: commonParam=blah, commonName=name2

    So my first hope was that there is a ItemProcessor in Spring Batch that allows you to return a list of results - but I could not find that.
    (something like this)
    public interface ItemProcessor<I, O> {
    	List<O> process(I item) throws Exception;
    Is there any way I can accomplish this writing of multiple permutations of one Item?

    Thanks in advance

  • #2
    You're going to want to write a custom ItemReader that wraps the StaxEventItemReader. This custom reader will read the XML file via the StaxEventItemReader and build the appropriate object as needed. Do keep in mind that state management will be tricky for restarts, but should be possible.


    • #3
      Thanks for the reply, I guess that's what I'll do then