0

I am trying to convert a csv file into JSON using Spring Integration but I could not find the suitable command in the xml file

I have csv file with header for example

empID, empName, dateOfBirth, Salary
1, Alice, 1990-05-14, 1000
2, Bob, 1991-06-15, 1100
3, Charlie, 1992-07-16, 1500

will become:

[
  {
    "ID": 1,
    "Name": "Alice",
    "dateOfBirth": "1990-05-14",
    "Salary": 1000
  },
  {
    "ID": 2,
    "Name": "Bob",
    "dateOfBirth": "1991-06-15",
    "Salary": 1100
  },
  {
    "ID": 3,
    "Name": "Charlie",
    "dateOfBirth": "1992-07-16",
    "Salary": 1500
  }
]

notice in the way i have also done some header name mapping "empID" become "ID" and "empName" become "Name"

1 Answer 1

2

I would suggest you take a look to the Spring Batch FlatFileItemReader: https://docs.spring.io/spring-batch/4.0.x/reference/html/readersAndWriters.html#flatFiles

A flat file is any type of file that contains at most two-dimensional (tabular) data. Reading flat files in the Spring Batch framework is facilitated by the class called FlatFileItemReader, which provides basic functionality for reading and parsing flat files. The two most important required dependencies of FlatFileItemReader are Resource and LineMapper.

You can use it from the <int:transformer>.

When you done with this you can simply use <int:object-to-json-transformer> to generate a JSON based on the intermediate POJO or just Map returned from that transformer based on the FlatFileItemReader.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.