I am marshalling and unmarshalling using spring jaxb2marshaller. it is working for version 10 except now I have to support two different version (say version 01, and 10) of xsd schema. how to set jaxb2marshaller to scan package based on the xsd version. My parsing code is
public void parseSampleFile(String fileLocation) throws FileNotFoundException, XMLStreamException {
InputStream inputStream = getFilePathInputStream(fileLocation);
XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
XMLStreamReader xsr = xmlInputFactory.createXMLStreamReader(inputStream);
XMLReaderWithoutNamespace xmlStreamReader = new XMLReaderWithoutNamespace(xsr);
StAXSource stAXSource = new StAXSource(xmlStreamReader);
// skip to the first element to reach Document
while (xmlStreamReader.hasNext() && !xmlStreamReader.isStartElement()) {
xmlStreamReader.next();
}
while (xmlStreamReader.getEventType() == XMLStreamConstants.START_ELEMENT) {
switch (xmlStreamReader.getLocalName()) {
case "Hdr":
header = (Header) jaxb2Marshaller.unmarshal(stAXSource);
xmlStreamReader.nextTag();
break;
case "SomeInf":
instruction = (Instruction) jaxb2Marshaller.unmarshal(stAXSource);
xmlStreamReader.nextTag();
break;
default:
xmlStreamReader.nextTag();
}
}
}
and I am setting jaxb2marshler in config file as
@Bean
Jaxb2Marshaller jaxb2Marshaller() {
Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
jaxb2Marshaller.setPackagesToScan("com.sample.version10.model");
return jaxb2Marshaller;
}