Unloading from tables with data transformation using Spring Batch

171 Views Asked by At

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
0

There are 0 best solutions below