I am building a parser for VAST documents, which are XML documents for which there is an official XSD, with a couple of versions : https://github.com/InteractiveAdvertisingBureau/vast/tree/master
I need to be able to unmarshal incoming XML, so I have generated the model using jaxb2-maven-plugin.
I need to be able to process incoming XML that may or may not mention the namespace : my problem is that it works when there's a namespace, but it doesn't when there's none.
Following https://stackoverflow.com/a/8717287/3067542 and https://docs.oracle.com/javase/6/docs/api/javax/xml/bind/Unmarshaller.html#unmarshalByDeclaredType , I understand that there's a workaround, because I know the target class type, so I can force to unmarshall to that class, whether there's a namespace or not.
Here's my code (also available here on github )
JAXBContext jc = JAXBContext.newInstance(VAST.class);
Unmarshaller u = jc.createUnmarshaller();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(new StringReader(xmlString)));
JAXBElement<VAST> foo = u.unmarshal( doc, VAST.class);
return new CustomVast(foo.getValue());
When running the test, I see that the inner classes are not populated :
Am I missing something ? is there an additional flag to set when generating the classes with jaxb2-maven-plugin so that it will work ?

This answer is clearly unoptimize but will give you hints on how to get it work on both namespaced-unnamespaced XML for 4.2 version :
Here is the body method of
parseXmlThe
src/main/resources/xslt/vast_4.2.xsltis :With that, both unit-tests are working for 4.2 part.