问题
I have followed the below procedures:
- Generated client files in eclipse using WSDL (Apache Axis 1).
- Using JAXB to unmarshal the request XML and then call the webservice.
If I use JDK 1.8.077 then the XML is getting parsed successfully. If I use any other JDK like version 1.8.102 or 1.8.112 JAXB is unable to parse properly and returns a null
value for the element.
Could anyone please suggest me the issue here?
回答1:
I can confirm the same faulty behavior with 1.8.111, after downgrading to 1.8.74 JAXB was able to parse properly.
Version 1.8.111:
JAXBContext.createUnmarshaller().unmarshal(new StreamSource(...), MyType.class).getValue()
returns a null
回答2:
One of the possible reason for the issue is with the parser expecting the code to provide support for XML namespace with later versions of JDK 1.8.
In case you are using the SAX based parser to parse the XML document, make sure you set the namespaceAware API to true
final SAXParserFactory sax = SAXParserFactory.newInstance(); sax.setNamespaceAware(true);
By default the value is set as false
I faced the same issue using the JDK version 1.8.121 & 1.8.131 with the SAX based parser and the issue got resolved by simply setting the value true for namespaceAware API for SAXParserFactory instance.
NOTE: The JAXB classes were generated from eclipse
来源:https://stackoverflow.com/questions/41608667/axis-jaxb-unmarshal-not-working-with-any-jdk-except-jdk-1-8-077