Skip to content

Instantly share code, notes, and snippets.

@dannyduc
Created August 16, 2013 14:00
Show Gist options
  • Save dannyduc/6250195 to your computer and use it in GitHub Desktop.
Save dannyduc/6250195 to your computer and use it in GitHub Desktop.
Sample Jersey Client code to post JSON data
String uri = "https://developer.ingenuity.com/datastream/api/v1/activations/a9ab2c34-01b5-4473-864d-0d2f008ae090-5";
String input = "[{\"sampleId\":\"33\",\"activationCode\":\"Lab-act-code-xxx-zzz\"}]";
Client client = Client.create();
ClientResponse response = client.resource(uri)
.type(MediaType.APPLICATION_JSON)
.header("Authorization", "xxx")
.post(ClientResponse.class, input);
System.out.println("StatusCode: " + response.getStatus());
ObjectMapper objectMapper = new ObjectMapper();
InputStream stream = response.getEntityInputStream();
Map activationMap = objectMapper.readValue(stream, Map.class);
stream.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment