use of org.json.JSONObject in project spring-boot-admin by codecentric.
the class ApplicationTest method test_1_5_json_format.
@Test
public void test_1_5_json_format() throws Exception {
String json = new JSONObject().put("name", "test").put("managementUrl", "http://test").put("healthUrl", "http://health").put("serviceUrl", "http://service").put("metadata", new JSONObject().put("labels", "foo,bar")).toString();
Application value = objectMapper.readValue(json, Application.class);
assertThat(value.getName(), is("test"));
assertThat(value.getManagementUrl(), is("http://test"));
assertThat(value.getHealthUrl(), is("http://health"));
assertThat(value.getServiceUrl(), is("http://service"));
assertThat(value.getMetadata(), is(Collections.singletonMap("labels", "foo,bar")));
}
use of org.json.JSONObject in project spring-boot-admin by codecentric.
the class ApplicationTest method test_healthUrl_expected.
@Test(expected = IllegalArgumentException.class)
public void test_healthUrl_expected() throws Exception {
String json = new JSONObject().put("name", "test").put("managementUrl", "http://test").put("healthUrl", "").put("serviceUrl", "http://service").toString();
objectMapper.readValue(json, Application.class);
}
use of org.json.JSONObject in project spring-boot-admin by codecentric.
the class ApplicationTest method test_1_4_json_format.
@Test
public void test_1_4_json_format() throws Exception {
String json = new JSONObject().put("name", "test").put("managementUrl", "http://test").put("healthUrl", "http://health").put("serviceUrl", "http://service").put("statusInfo", new JSONObject().put("status", "UNKNOWN")).toString();
Application value = objectMapper.readValue(json, Application.class);
assertThat(value.getName(), is("test"));
assertThat(value.getManagementUrl(), is("http://test"));
assertThat(value.getHealthUrl(), is("http://health"));
assertThat(value.getServiceUrl(), is("http://service"));
}
use of org.json.JSONObject in project coinbase-bitmonet-sdk by coinbase.
the class JSONUtils method extractIntValueFromJSONResponse.
public static int extractIntValueFromJSONResponse(HttpResponse response, String key) throws JSONException, IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
String json = reader.readLine();
// Extract access token, refresh token and the refresh time
JSONObject jObject = new JSONObject(json);
try {
return jObject.getInt(key);
} catch (JSONException e) {
e.printStackTrace();
}
UserProfileSettings.getInstance().saveCoinbaseOAuthStatus(false);
return -1;
}
use of org.json.JSONObject in project coinbase-bitmonet-sdk by coinbase.
the class OAuthHelperUtils method extractOAuthParamatersFromJSON.
private void extractOAuthParamatersFromJSON(HttpResponse response) throws JSONException, IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
String json = reader.readLine();
// Extract access token, refresh token and the refresh time
JSONObject jObject = new JSONObject(json);
try {
UserProfileSettings.getInstance().saveAccessToken(jObject.getString(Constants.ACCESS_TOKEN));
UserProfileSettings.getInstance().saveRefreshToken(jObject.getString(Constants.REFRESH_TOKEN));
UserProfileSettings.getInstance().saveRefreshTime(jObject.getInt(Constants.ACCESS_TOKEN_EXPIRY_TIME));
} catch (JSONException e) {
e.printStackTrace();
}
}
Aggregations