简体   繁体   中英

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

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.

I don't think this is possible -- you will most likely have to create some sort of wrapper or DTO around your Collection/Map. This: Using JAXB to unmarshal/marshal a List<String> I believe is related to your use-case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM