You will need to have Jackson jars in your classpath (or any other XML / JSON to Map mapper)
You probably don't want to pass the map on the @PathParam
, for aesthetical, convention and security reasons. You usually pass a JSON / XML object as the request body, e.g. using a POST / PUT
@POST
@Path("/anypath")
@Consumes({"text/xml", "application/json"})
public User find(HashMap<String, String> map) {
//magic should happen
}
Then just pass a POST / PUT request with content type application/json or text/xml that has
e.g.
{
"key1": "value1"
"key2": "value2"
}
If you have the right Jackson / Moxy etc mapper in the classpath, it will do the conversion between the JSON / XML format to a java.util.Map
(or even a POJO) for you
The @Produces
is only needed if you intend to also return XML / JSON, but since you are expecting either XML or JSON, then having a @Consumes
makes sense here.
However, if you must pass the JSON object on a GET request, e.g. as a request param, take a look at this question: Convert JSON query parameters to objects with JAX-RS
p.s. for xml the mime is text/xml
and not application/xml