How to fix things
Reject at the correct level
You are currently unmounting the XML node that corresponds to the soap:Body element, instead you need to go down to the HotelListResponse element and cancel it.
You can try the following:
DOMSource source = new DOMSource(sb.getFirstChild().getFirstChild());
Keep track of name qualifications
In the XML that you have defined, all elements are displayed using http://v3.hotel.wsapi.ean.com/ , the document you are trying to decouple does not have this qualification in the namespace, so you must remove the @XmlSchema annotation from package-info class.
Use Unmarshaller instead of JAXB.unmarshal
Instead of doing the following:
results = (HotelListResponse) JAXB.unmarshal(source, HotelListResponse.class);
I would recommend:
JAXBContext jc = JAXBContext.newInstance(HotelListResponse.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); results = unmarshaller.unmarshal(source, HotelListResponse.class).getValue();
What is happening now
When you use the unmarshal method, which takes a class parameter, you tell JAXB which class is XML compliant, rather than automatically detecting it as the root element.
results = (HotelListResponse) JAXB.unmarshal(source, HotelListResponse.class)
Because the level of the XML document is incorrect, JAXB cannot match it with your domain model. Therefore, only the default values ​​are populated. This is why the result is populated with the values 0 or false .
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <HotelListResponse xmlns="http://v3.hotel.wsapi.ean.com/"> <numberOfRoomsRequested>0</numberOfRoomsRequested> <moreResultsAvailable>false</moreResultsAvailable> <HotelList size="0" activePropertyCount="0"/> </HotelListResponse>