aspose file tools*
The moose likes Spring and the fly likes Issue with Spring OXM When Unmarshalling XML data(oxm:jaxb2-marshaller) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Issue with Spring OXM When Unmarshalling XML data(oxm:jaxb2-marshaller)" Watch "Issue with Spring OXM When Unmarshalling XML data(oxm:jaxb2-marshaller)" New topic
Author

Issue with Spring OXM When Unmarshalling XML data(oxm:jaxb2-marshaller)

Varshini Priya
Ranch Hand

Joined: Feb 17, 2008
Posts: 93

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

FilterSelectionResponse obj = (FilterSelectionResponse) this.unmarshaller.unmarshal(new StreamSource(is));

Also below is the code that I have included in my appplicationcontext.xml file



Im passing an InputStream Object as an argument to StreamSource constructor. Please help resolve this issue. Thanks in Advance.
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1680
    
    7

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.

Read this blog to get acquainted http://blog.springsource.org/2009/03/27/rest-in-spring-3-resttemplate/

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.


[How To Ask Questions][Read before you PM me]
Varshini Priya
Ranch Hand

Joined: Feb 17, 2008
Posts: 93

Hi Bill,

Thanks for the response. Please find the stack trace below for the null pointer exception.





Also I tried the restTemplate that you specified in the above section. But I seem to get a Null Pointer error there as well. Any help on resolving is greatly appreciated.Thanks
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1680
    
    7

Ok so exactly what is on the lines specified below?

at com.bizdelegate.ReBusinessDelegate.getFilterSelectionList(RepBusinessDelegate.java:91)
at com.managedbeans.DemandManagedBean.getFilterSelectionList(DemandManagedBean.java:306)

Also have you walked through with a debugger to identify exactly what is null?

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Issue with Spring OXM When Unmarshalling XML data(oxm:jaxb2-marshaller)