springspring-batchedi

Spring Batch - EDI file reader


I want to read EDI files and transform them into POJO in Spring Batch. I couldn't find any example of that working along with Spring Batch.

My Edi files can contain up to hundreds of segments that should be mapped to a List of objects.

I know I can use smooks framework to tranform EDI file into pojo, however it would transform the file in one chunk. My application would not read file in multiple chunks, like it does right now for xml, json etc. So the main feature of spring batch would be lost.

Is there any clever way of doing it?


Solution

  • I'm not sure I follow but it should be possible to do what you're asking for in Smooks. Smooks can ingest an EDI file in chunks and bind each chunk to a POJO or java.util.Map (i.e., virtual object model). You can then choose to:

    1. Accumulate the items in a list, or
    2. Process each item as soon as it's created with a org.smooks.api.bean.lifecycle.BeanContextLifecycleObserver and discard it after processing in order to save memory.

    The Smooks fundamentals section gives a good overview of the framework. There's also an example available demonstrating how to bind EDI to POJOs.