@Override @POST @Path("/deviceid/") public String usernameFromDeviceId(@FormParam("deviceid") final String id) { Device device = findDeviceByDeviceId(id); if (device == null) { return "{\"deviceExists\":false}"; } if (device.getUsername() == null || device.getUsername().length() == 0) { return "{\"deviceExists\":true,\"hasUsername\":false}"; } else { return "{\"deviceExists\":true,\"hasUsername\":true,\"username\":\"" + device.getUsername() + "\"}"; } }