AXIS-JAXB Unmarshal does not work with any JDK except jdk 1.8.077

I performed the following procedures:

  • Generated client files in eclipse using WSDL (Apache Axis 1).
  • Using JAXB to cancel an XML request and then invoke the web service.

If I use JDK 1.8.077, then XML is parsed successfully. If I use any other JDK version of version 1.8.102 or 1.8.112, JAXB will not be able to parse correctly and returns a null value for the element.

Can anyone suggest me this problem?

+2
source share
2 answers

I can confirm the same erroneous behavior with 1.8.111, after lowering to 1.8.74 JAXB was able to parse correctly.

Version 1.8.111:

 JAXBContext.createUnmarshaller().unmarshal(new StreamSource(...), MyType.class).getValue() 

returns null

0
source

One possible cause of the problem is that the parser expects the code to provide support for the XML namespace with later versions of JDK 1.8.

If you use the SAX parser to parse an XML document, make sure the namespaceAware API is set to true

final SAXParserFactory sax = SAXParserFactory.newInstance (); sax.setNamespaceAware (true);

The default value is set to false.

I ran into the same problem using the JDK versions 1.8.121 and 1.8.131 with the SAX-based parser, and the problem was solved by simply setting true for the namespaceAware API for the SAXParserFactory instance.

NOTE. JAXB classes were created from eclipse

0
source

Source: https://habr.com/ru/post/1260588/


All Articles