-1

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
0

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.