aspose file tools*
The moose likes Web Services and the fly likes Restful service endpoint to produce XML response for ResponseEntity< HashMap<String, Serializable>> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Restful service endpoint to produce XML response for ResponseEntity< HashMap<String, Serializable>>" Watch "Restful service endpoint to produce XML response for ResponseEntity< HashMap<String, Serializable>>" New topic
Author

Restful service endpoint to produce XML response for ResponseEntity< HashMap<String, Serializable>>

Ajil Mohan
Greenhorn

Joined: Feb 20, 2010
Posts: 8
I am trying to implement a RESTful service endpoint which produces XML responses. The return entity for this service call is a HashMap which has the data for the output to be generated. But I keep getting the following exception while invoking the service:

HttpMediaTypeNotAcceptableException: Could not find acceptable representation

To investigate the issue, I wrote another endpoint which produces a response for a single object (say, Employee). I have annotated this class with @XmlRootElement and invoking it works just fine. If I remove the @XmlRootElement annotation from the Employee class, this endpoint will also fail and give the same exception which I mentioned above.

As per my understanding the root object in the ResponseEntity should be annotated with @XmlRootElement. My problem centers around how to use this annotation on collections like Map, List etc..

All help appreciated, thanks


SCJP 1.5
H Paul
Ranch Hand

Joined: Jul 26, 2011
Posts: 461
    
    4
1. If your rest engine rely on JAXB, then use XmlAdapter and @XmlJavaTypeAdapter
2. Or implements MessageBodyWriter.

There are examples on the net. Just Google.
 
Consider Paul's rocket mass heater.
 
subject: Restful service endpoint to produce XML response for ResponseEntity< HashMap<String, Serializable>>