javaxmljaxbapache-axisaxis2c

Difficulty unmarshalling an XML string into an AXIS2/xmlbeans generated object


I am currently facing an issue with converting an XML string into an object generated with AXIS2 and JAXB (unmarshalling). I'm having trouble accessing the attributes of the object using the getter methods. Strangely, all the getter methods of the printResult object return null values. However, when I invoke the toString() method, the complete object with all the set values is displayed.

I'm perplexed about why the getter methods are not returning any values and how I can retrieve the attributes using the getter methods. Any help or suggestions would be greatly appreciated.

Thank you in advance!

PrintResultType printResult = PrintResultType.Factory.parse(xmlResponse);  

PrintDetailsType[] arr = printResult.getPrintDetailsArray();  

log.info("arr == null: " + (arr == null) + " arr size: " + arr.length);
// arr == null ? : false arr size 0

BaggageType baggageType = printResult.getBaggageType();
log.info("BaggageType == null: " + (BaggageType == null));
// BaggageType == null : true

log.info(("Unmarshalled printResult:\n" + printResult.toString()));
// The object is logged with all subobjects and array

Solution

  • I have discovered that the parse(..)-method only stored the XML string in the object, but the attributes were not set.

    The "xmlText()" method allows retrieving the string stored in the object, which was also outputted by the "toString()" method. For this reason I wrongly assumed that the attributes were set in the object. No error message is logged during parsing which would indicate this.

    I modified the input XML string, adding a required XML prefix to all tags in the XML string, and now it works.