JAXB unmarshall with namespaces and prefix

后端 未结 3 1883
暗喜
暗喜 2020-11-30 04:34

I am using JAXB to parse xml elements from the SOAP response. I have defined POJO classes for the xml elements. I have tested pojo classes without namespace and prefix its w

3条回答
  •  抹茶落季
    2020-11-30 05:02

    Just wanted to add onto the existing answers -- while unmarshalling if the XML document is not namespace aware you might receive an error: javax.xml.bind.UnmarshalException: unexpected element (uri:"http://some.url";, local:"someOperation")

    If this is the case you can simply use a different method on the unmarshaller:

    Unmarshaller unmarshaller = JAXBContext.newInstance(YourObject.class).createUnmarshaller();
    JAXBElement element = unmarshaller.unmarshal(message.getSOAPBody().extractContentAsDocument(), YourObject.class);
    YourObject yo = element.getValue();
    

提交回复
热议问题