Announcement Announcement Module
Collapse
No announcement yet.
Is there any JSON file item reader? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is there any JSON file item reader?

    Hi,

    My current batch is configured to work with FlatFileItemReader reading a plaintext:
    val-1 val-2 ... val-n

    Now the input file has changed to be in a JSON format:
    {"inp-1":"val-1", "inp-2":"val-2", ... ,"inp-n":"val-n"}

    Does spring released such a JSON reader?

    What do you suggest doing?
    1. public class UsageLogReaderForJson extends FlatFileItemReader
    & override the read() method?
    2. Don't use spring batch & write everything from scrach dedicated to
    JSON.

    Thanks.

  • #2
    I would create an implementation of the LineTokenizer that converts JSON rather than a fixed length or delimited line. As long as your individual elements are all on one line, it's pretty trivial. However, if it spans multiple lines, you may need to think of using a LineMapper (if using 2.0) or potentially extending the reader as you mentioned. I would also take a look at the line seperator policy, as you may be able to create one of those for JSON, which would then change how the reader defines a 'line'.

    Comment


    • #3
      Thanks Lucas for your reply.

      I did exactly as you first suggested by implementing my own line tokenizer using gson (google tool for json parser).

      Take care.

      Comment


      • #4
        It sounds like something that may be needed generally, if possible, perhaps you can create a jira issue and attach your solution?

        Comment


        • #5
          Good point, here it is:

          http://jira.springframework.org/browse/BATCH-1246

          Thanks.

          Comment

          Working...
          X