I have different JSON files and need to read, process and write the containing JSON objects of a JSON array.
The output format (more specific: the output class) is for all files the same. Lets call it OutputClass
. Hence the item processor is something like ItemProcessor<X, OutPutClass>
. Where X
is the class of the specific JSON file.
The difference between files are:
- The JSON array / the information is at a different position in every JSON file
- The structure of the JSON objects in the JSON array are different (the objects in file
a
have a different syntax than the ones in fileb
)
I already came across of @StepScope
and was able to dynamically generate a reader (depending on job parameters) which starts reading at a different position in the JSON structure.
But I have no idea how to dynamically choose an ItemProcessor depending on the job parameters. Because I got many different JSON files and want to reduce the amount of code to write for each file.
Advertisement
Answer
Since you were able to create a dynamic item reader based on job parameters by using the a step-scoped bean (which is the way I would do it too), you can use the same approach to create a dynamic item processor as well.