@Path("/{id}")
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response updateTodo(@Context UriInfo info, @PathParam("id") String id, Map map) {
Todo existing = todoService.getById(id);
if (existing == null) {
throw new UnknownResourceException();
}
//typically done via a framework call to automate this for any type of entity:
if (map.containsKey("name")) {
existing.setName(String.valueOf(map.get("name")));
}
if (map.containsKey("done")) {
existing.setDone(Boolean.valueOf(String.valueOf(map.get("done"))));
}
existing = todoService.save(existing);
return Response.ok(new TodoResource(info, existing), MediaType.APPLICATION_JSON).build();
}