0

I want to do a dump from tables using Spring Batch. I need to dump data from the customer input table to the customer_data output table. The customer table has a data column of type String (jsonb). I need to get json from the data column and convert it to flatten map format, then dump this data into the field (key) and value (value) columns in the customer_data table.

Is there a nice solution how to do this with Spring Batch? I'm not sure if this needs to be implemented in the InputRowMapper because there are many records to be saved to a new customer_data table.

Input (customer):

@Data
@Accessors(chain = true)
public class CustomerDataInput {

    private Long id;
    private String data;
}

Where data:

{
   "template":"test",
   "description":"example"
}

Output (customer_data):

@Data
@Accessors(chain = true)
public class CustomerDataOutput {

    private Long jobId;
    private Long id;
    private Long dataId;
    private String field;
    private Object value;
}

I expect this:

job_id id data_id field value
1 1 1 template test
1 2 1 description example
pickstar
  • 21
  • 5
  • Does this mean that an input item is transformed to multiple output items? Please share an example with a couple input/output records to explain your requirement. Also, please share your code with your specific issue to be able to help you efficiently. – Mahmoud Ben Hassine Jun 21 '21 at 07:41
  • [Mahmoud Ben Hassine](https://stackoverflow.com/users/5019386/mahmoud-ben-hassine) Yes that's right. I have added an example of input / output data. – pickstar Jun 21 '21 at 09:39
  • [Mahmoud Ben Hassine](https://stackoverflow.com/users/5019386/mahmoud-ben-hassine) As I understand it, I need to use an ItemWriter in the CustomerDataProcessor class that will work with List. But I can't seem to find a working implementation to write a list of entities. – pickstar Jun 21 '21 at 20:54
  • Does this answer your question? [Spring Batch - Using an ItemWriter with List of Lists](https://stackoverflow.com/questions/37866312/spring-batch-using-an-itemwriter-with-list-of-lists) – Mahmoud Ben Hassine Jun 22 '21 at 10:14
  • [Mahmoud Ben Hassine](https://stackoverflow.com/users/5019386/mahmoud-ben-hassine) thanks for the answer, I have researched the given example, but I get NullPointerException at delegate.write(consolidatedList) even though I am doing listUnpackingItemWriter.setDelegate(itemWriter) in my CustomerDataStepConfiguration class – pickstar Jun 22 '21 at 11:29

0 Answers0