0
  1. reader -> injest a class named Person
  2. 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)
  3. 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)

Array
  • 1
  • https://stackoverflow.com/questions/27836312/use-spring-batch-to-write-in-different-data-sources I have read everything here and it looks similar to my problem, but I do not understand how should I write Unwrapper, cause the problem is the same: I do not know how to choose which field should be used by the writer. – Array Dec 02 '19 at 18:47
  • Can you explain what are you trying to achieve without referring to Spring Batch? What is the input/output of your job? – Mahmoud Ben Hassine Dec 03 '19 at 11:01

0 Answers0