There are lots of questions on returning serialized HashMap, but I didn't find a very good answer.
Now I just want to simply create a rest service like this:
@XmlElement(name = "Calibration") private HashMap<String, Double> entry = new HashMap<String, Double>(); Then in my REST service:
@GET @Produces(MediaType.APPLICATION_JSON) @Path("/entry") public HashMap<String, Double> current() { System.out.println("calibration request"); entry.put("test", 3.00); return entry; } It throws javax.ws.rs.WebApplicationException when the service is called:
com.sun.jersey.api.MessageException: A message body writer for Java class java.util.HashMap, and Java type java.util.HashMap, and MIME media type application/json was not found.
My pom.xml, in case it is useful:
<dependency> <groupId>com.sun.grizzly</groupId> <artifactId>grizzly-servlet-webserver</artifactId> <version>1.9.18-i</version> </dependency> <dependency> <groupId>com.sun.grizzly</groupId> <artifactId>grizzly-comet-webserver</artifactId> <version>1.9.46</version> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-grizzly</artifactId> <version>1.9.1</version> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-json</artifactId> <version>1.9.1</version> </dependency> I'm using Grizzly as webContainer.