List of usage examples for javax.json JsonObject getJsonNumber
JsonNumber getJsonNumber(String name);
From source file:com.buffalokiwi.aerodrome.jet.Utils.java
public static BigDecimal getJsonNumber(final JsonObject obj, final String property) { try {// w ww .ja v a 2s .c o m return obj.getJsonNumber(property).bigDecimalValue(); } catch (ClassCastException e) { return new BigDecimal(0); } }
From source file:com.buffalokiwi.aerodrome.jet.Utils.java
public static Money jsonNumberToMoney(final JsonObject json, final String property) { if (json == null || property == null || property.isEmpty()) return new Money(); try {//w w w.ja va 2s .c o m return jsonNumberToMoney(json.getJsonNumber(property)); } catch (Exception e) { return new Money(); } }
From source file:com.buffalokiwi.aerodrome.jet.Utils.java
public static BigDecimal jsonNumberToBigDecimal(final JsonObject json, final String property, final int defaultValue) { if (json == null || property == null || property.isEmpty()) return new BigDecimal(defaultValue); try {/* w ww. j a va 2 s .c o m*/ return jsonNumberToBigDecimal(json.getJsonNumber(property), defaultValue); } catch (Exception e) { return new BigDecimal(defaultValue); } }
From source file:org.traccar.geolocation.UniversalGeolocationProvider.java
@Override public void getLocation(Network network, final LocationProviderCallback callback) { try {// w w w. j a v a 2s. co m String request = Context.getObjectMapper().writeValueAsString(network); Context.getAsyncHttpClient().preparePost(url) .setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .setHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(request.length())).setBody(request) .execute(new AsyncCompletionHandler() { @Override public Object onCompleted(Response response) throws Exception { try (JsonReader reader = Json.createReader(response.getResponseBodyAsStream())) { JsonObject json = reader.readObject(); if (json.containsKey("error")) { callback.onFailure(new GeolocationException( json.getJsonObject("error").getString("message"))); } else { JsonObject location = json.getJsonObject("location"); callback.onSuccess(location.getJsonNumber("lat").doubleValue(), location.getJsonNumber("lng").doubleValue(), json.getJsonNumber("accuracy").doubleValue()); } } return null; } @Override public void onThrowable(Throwable t) { callback.onFailure(t); } }); } catch (JsonProcessingException e) { callback.onFailure(e); } }
From source file:com.rhcloud.javaee.movieinfo.business.actor.boundry.ActorResourceIT.java
@Test public void actor_integration_OptimisticLockingCheck() { // Get Actor//from w ww .j a va 2s . co m Response getResponse = null; try { getResponse = provider.target().path(FORWARD_SLASH + ACTORS_PATH + FORWARD_SLASH + 1) .request(APPLICATION_JSON).get(); } finally { System.out.println("Server responded ? " + (getResponse != null)); assumeThat(getResponse, is(notNullValue())); } final String fn = "John"; final String ln = "Doe"; // Post Actor Response postResponse = provider.target().path(FORWARD_SLASH + ACTORS_PATH).request(APPLICATION_JSON) .post(Entity.json(createActor(fn, ln))); assertThat(postResponse, is(successful())); String location = postResponse.getHeaderString("Location"); assertThat(location, is(notNullValue())); System.out.println( "ActorResourceIT.actor_integration_OptimisticLockingCheck() Post Actor Response Location : " + location); try { // Get Actor Response actorResponse = provider.target(location).request(APPLICATION_JSON).get(); assertThat(actorResponse, is(successful())); JsonObject actor = actorResponse.readEntity(JsonObject.class); assertThat(actor.getString(FIRSTNAME), is(equalTo(fn))); assertThat(actor.getString(LASTNAME), is(equalTo(ln))); assertThat(actor.keySet(), hasItem(VERSION)); long version = actor.getJsonNumber(VERSION).longValue(); System.out.println("ActorResourceIT.actor_integration_OptimisticLockingCheck() Get Actor : " + actor); // Update Actor Once final String newFn = "Jane"; JsonObject actorUpdate = Json.createObjectBuilder().add(FIRSTNAME, newFn).add(LASTNAME, ln) .add(VERSION, version).build(); Response putResponse = provider.target(location).request(APPLICATION_JSON) .put(Entity.json(actorUpdate)); assertThat(putResponse, is(successful())); JsonObject updatedActor = putResponse.readEntity(JsonObject.class); assertThat(updatedActor.getString(FIRSTNAME), is(equalTo(newFn))); assertThat(updatedActor.getString(LASTNAME), is(equalTo(ln))); System.out.println( "ActorResourceIT.actor_integration_OptimisticLockingCheck() update Actor once Response : " + updatedActor); // Update Actor Second time final String newFn2 = "Jamie"; actorUpdate = Json.createObjectBuilder().add(FIRSTNAME, newFn2).add(LASTNAME, ln).add(VERSION, version) .build(); putResponse = provider.target(location).request(APPLICATION_JSON).put(Entity.json(actorUpdate)); assertThat(putResponse.getStatus(), is(409)); System.out.println( "ActorResourceIT.actor_integration_OptimisticLockingCheck() update Actor second time Response : " + putResponse); final MultivaluedMap<String, Object> putResponseHeaders = putResponse.getHeaders(); putResponseHeaders.forEach((key, value) -> { System.out.println( "actor_integration_OptimisticLockingCheck() : key : " + key + ", value : " + value); }); assertThat((String) putResponseHeaders.getFirst("Cause"), containsString("There was a conflict. Details are :")); assertThat((String) putResponseHeaders.getFirst("additional-info"), containsString("Row was updated or deleted by another transaction")); } finally { // Delete Actor Response deleteActor = provider.target(location).request(APPLICATION_JSON).delete(); assertThat(deleteActor, is(successful())); System.out.println("ActorResourceIT.actor_integration_OptimisticLockingCheck() Delete Actor Response : " + deleteActor); } }
From source file:jp.co.yahoo.yconnect.core.oidc.IdTokenDecoder.java
/** * IdToken?//from ww w. j a v a2 s. co m * * @return IdTokenObject * @throws DataFormatException */ public IdTokenObject decode() throws DataFormatException { HashMap<String, String> idToken = this.splitIdToken(); // Header String jsonHeader = idToken.get("header"); JsonReader jsonHeaderReader = Json.createReader(new StringReader(jsonHeader)); JsonObject rootHeader = jsonHeaderReader.readObject(); jsonHeaderReader.close(); JsonString typeString = rootHeader.getJsonString("typ"); String type = typeString.getString(); JsonString algorithmString = rootHeader.getJsonString("alg"); String algorithm = algorithmString.getString(); // Payload String jsonPayload = idToken.get("payload"); JsonReader jsonPayloadReader = Json.createReader(new StringReader(jsonPayload)); JsonObject rootPayload = jsonPayloadReader.readObject(); jsonPayloadReader.close(); JsonString issString = rootPayload.getJsonString("iss"); String iss = issString.getString(); JsonString userIdString = rootPayload.getJsonString("user_id"); String userId = userIdString.getString(); JsonString audString = rootPayload.getJsonString("aud"); ArrayList<String> aud = new ArrayList<String>(); aud.add(audString.getString()); JsonNumber expString = rootPayload.getJsonNumber("exp"); int exp = expString.intValue(); JsonNumber iatString = rootPayload.getJsonNumber("iat"); int iat = iatString.intValue(); JsonString nonceString = rootPayload.getJsonString("nonce"); String nonce = nonceString.getString(); // signature String signature = idToken.get("signature"); // ??? return new IdTokenObject(type, algorithm, iss, userId, aud, nonce, exp, iat, signature); }
From source file:edu.harvard.hms.dbmi.bd2k.irct.ri.exac.EXACResourceImplementation.java
private String getValue(JsonObject obj, String field) { if (field.contains(".")) { String thisField = field.split("\\.")[0]; String remaining = field.replaceFirst(thisField + ".", ""); return getValue(obj.getJsonObject(thisField), remaining); }/*w ww . j a va 2 s .co m*/ if (obj.containsKey(field)) { ValueType vt = obj.get(field).getValueType(); if (vt == ValueType.NUMBER) { return obj.getJsonNumber(field).toString(); } else if (vt == ValueType.TRUE) { return "TRUE"; } else if (vt == ValueType.FALSE) { return "FALSE"; } return obj.getString(field); } return ""; }
From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java
public long jsonLong(JsonObject object, String key) throws BtcException { JsonNumber number = object.getJsonNumber(key); return (number == null) ? 0 : number.longValueExact(); }
From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java
public BigDecimal jsonDouble(JsonObject object, String key) throws BtcException { JsonNumber number = object.getJsonNumber(key); return (number == null) ? BigDecimal.ZERO : number.bigDecimalValue(); }
From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java
public long jsonLong(JsonObject object, String key, long defaultValue) throws BtcException { JsonNumber number = object.getJsonNumber(key); return (number == null) ? defaultValue : number.longValueExact(); }