Im trying to unmarshall the XML data into Object using Spring OXM Marshaller. Please find the code below that we have written for converting the same. In our project, we are using Rest Service to retrieve the data from the database. When I try to run the url in the browser, it fetches the xml data fine. But I getting an issue when Im trying to unmarshall using the Spring OXM Marshaller.
Im receiving a null pointer error when trying to execute the below line
Ok so what is null the inputStream? It would really help if you posted the stack trace so that we can debug this a bit easier.
While you are working on getting that stack trace for us I will give you a few other alternatives for handling stuff like this:
First of all you can get rid of just about all of that code by using RestTemplate instead of httpClient. RestTemplate can be configured to use HttpClient to do its work but by default it just uses the standard java net stuff.
Now your rest call and unmarshalling will be reduced to one line:
Also if you are using 3.1.1 they added a packages to scan to org.springframework.oxm.jaxb.Jaxb2Marshaller which makes the oxm namespace useless and removes the need to define the pesky classes to be bound for every single object. To use that just declare a bean of type
org.springframework.oxm.jaxb.Jaxb2Marshaller and set the package(s) to scan for your JaxB annotated objects. After you do this either autowire or wire this bean into any class as you marshaller/unmarshaller. Remember you do need the very latest Spring for this one, RestTemplate has been there since 3.0 though.