Last active
October 6, 2015 09:12
-
-
Save judoole/7dc1203d282b27a40bbc to your computer and use it in GitHub Desktop.
Unmarshal a jax ws response to object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Using Spring to create a reader. Should be easy to write this yourself. | |
| //file is the xml response you got stripped of SoapEnvelope and SoapBody. | |
| def classpathResource: ClassPathResource = new ClassPathResource(file) | |
| def inputStream: InputStream = classpathResource.getInputStream() | |
| def xmlInputFactory: XMLInputFactory = XMLInputFactory.newInstance() | |
| def xmlReader: XMLStreamReader = xmlInputFactory.createXMLStreamReader(inputStream) | |
| //ObjectFactory you can find in your jax ws generated code | |
| val instance: JAXBContext = JAXBContext.newInstance(classOf[ObjectFactory]) | |
| val unmarshaller: Unmarshaller = instance.createUnmarshaller() | |
| //Unmarshal using JAXB, cast to JAXBElement. | |
| val response: JAXBElement[TheClassYouWanToUnmarshal] = unmarshaller.unmarshal(xmlReader).asInstanceOf[JAXBElement[TheClassYouWanToUnmarshal]] | |
| //Get the value. If no exceptions, use it in a test. | |
| val value: TheClassYouWanToUnmarshal = response.getValue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment