So I have a simple web service:
@WebMethod(operationName=\"getBookList\")
public HashMap getBookList()
{
HashMap
In order to help JAXB, you can 'wrap' your HashMap in a class and use the @XmlJavaTypeAdapter to make your custom serialization of the map to XML.
public class Response {
@XmlJavaTypeAdapter(MapAdapter.class)
HashMap books;
public HashMap getBooks() {
return mapProperty;
}
public void setBooks(HashMap map) {
this.mapProperty = map;
}
}
Then use this class as a return value of your WebMethod
@WebMethod(operationName="getBookList")
public Response getBookList()
{
HashMap books = new HashMap();
Book b1 = new Book(1,"title1");
Book b2 = new Book(2, "title2");
books.put(1, b1);
books.put(2, b2);
Response resp = new Response();
resp.setBooks(books);
return resp;
}
After all, you need to implement your adapter MapAdapter. There is several ways to do this, so I recommend you to check this