// curl -X POST -H 'Content-Type:application/json' --data // '{"name":"test","tags_vector":{"newyork":3,"sea":-1} }' // http://localhost:8680/rest/user @POST @Path("/add") @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public String addUser(User user) { assert user.getId() == null; api.addUser(user); return user.getId(); }
// either add or update @POST @Path("/") @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public String addUpdateUser(User user) { if (user.getId() == null) { System.out.println("adding user " + user); api.addUser(user); } else { System.out.println("updating user " + user); api.updateUser(user.getId(), user); } return user.getId(); }