- reader -> injest a class named Person
- processor -> injest Person, and returns a wrapper object, that has 3 fields, all of them are of type Person (1. inputPerson, 2. outputPerson, 3. output)
- writer -> injest this wrapper and should write first two fields in one file, and the third one in a second file as xml.
That is the code, that I have written for this problem:
@Bean
public CompositeItemWriter<Wrapper> compositeItemWriter(){
CompositeItemWriter writer = new CompositeItemWriter();
writer.setDelegates(Arrays.asList(firstTwoWriters(), thirdWriter));
return writer;
}
@Bean
public StaxEventItemWriter<Wrapper> firstTwoWriters() {
StaxEventItemWriter<Wrapper> xmlFileWriter = new StaxEventItemWriter<>();
xmlFileWriter.setRootTagName("something");
String outputName = applicationArguments.getOptionValues("output").get(0);
FileSystemResource outputResource = new FileSystemResource(outputName);
xmlFileWriter.setResource(outputResource);
Jaxb2Marshaller personMarshaller = new Jaxb2Marshaller();
scoringMapMarshaller.setClassesToBeBound(Person.class);
xmlFileWriter.setMarshaller(personMarshaller );
}
The problem is, that i cannot choose which field (inputPerson, outputPerson or output) should be used by this writer(which field should be converted to xml). Any ideas, how can I do this? (if possible with an example)