Example usage for com.google.gson JsonObject has

List of usage examples for com.google.gson JsonObject has

Introduction

In this page you can find the example usage for com.google.gson JsonObject has.

Prototype

public boolean has(String memberName) 

Source Link

Document

Convenience method to check if a member with the specified name is present in this object.

Usage

From source file:com.createtank.payments.coinbase.CoinbaseApi.java

License:Apache License

/**
 * Creates a new payment button, page, or iframe
 * @param name The name of the item for which you are collecting bitcoin. For example, Acme Order #123 or Annual Pledge Drive
 * @param amount Price as a decimal string, for example 1.23. Can be more then two significant digits if currency equals BTC.
 * @param currency Price currency as an ISO 4217 code such as USD or BTC. This determines what currency the price is shown in on the payment widget.
 * @param type One of buy_now, donation, and subscription.
 * @param style One of buy_now_large, buy_now_small, donation_large, donation_small, subscription_large, subscription_small, custom_large, custom_small, and none. none is used if you plan on triggering the payment modal yourself using your own button or link.
 * @param text Allows you to customize the button text on custom_large and custom_small styles.
 * @param desc Longer description of the item in case you want it added to the users transaction notes.
 * @param custom An optional custom parameter. Usually an Order, User, or Product ID corresponding to a record in your database.
 * @param callbackUrl A custom callback URL specific to this button. It will receive the same information that would otherwise be sent to your Instant Payment Notification URL. If you have an Instant Payment Notification URL set on your account, this will be called instead  they will not both be called.
 * @param successUrl A custom success URL specific to this button. The user will be redirected to this URL after a successful payment. It will receive the same parameters that would otherwise be sent to the default success url set on the account.
 * @param cancelUrl A custom cancel URL specific to this button. The user will be redirected to this URL after a canceled order. It will receive the same parameters that would otherwise be sent to the default cancel url set on the account.
 * @param infoUrl A custom info URL specific to this button. Displayed to the user after a successful purchase for sharing. It will receive the same parameters that would otherwise be sent to the default info url set on the account.
 * @param isVariablePrice Allow users to change the price on the generated button.
 * @param includeAddress Collect shipping address from customer (not for use with inline iframes).
 * @param includeEmail Collect email address from customer (not for use with inline iframes).
 * @return Json response containing the button information
 * @throws IOException/* w  ww . ja v  a2  s  . co m*/
 */
public JsonObject makeButton(String name, String amount, String currency, String type, String style,
        String text, String desc, String custom, String callbackUrl, String successUrl, String cancelUrl,
        String infoUrl, boolean isVariablePrice, boolean includeAddress, boolean includeEmail)
        throws IOException, UnsupportedRequestVerbException {

    JsonObject jsonRequest = createButtonRequestJson(name, type, amount, currency, style, text, desc, custom,
            callbackUrl, successUrl, cancelUrl, infoUrl, isVariablePrice, includeAddress, includeEmail);

    JsonObject resp = RequestClient.post(this, "buttons", jsonRequest, accessToken);

    return resp != null && resp.has("button") ? resp.getAsJsonObject("button") : null;
}

From source file:com.createtank.payments.coinbase.models.Address.java

License:Apache License

public static Address fromJson(JsonObject json) {
    return new Address(json.get("address").getAsString(),
            json.has("callback_url") && !json.get("callback_url").isJsonNull()
                    ? json.get("callback_url").getAsString()
                    : null,/*from   w ww  . ja v a2 s. c om*/
            json.has("label") && !json.get("label").isJsonNull() ? json.get("label").getAsString() : null,
            json.has("created_at") && !json.get("created_at").isJsonNull()
                    ? json.get("created_at").getAsString()
                    : null);
}

From source file:com.createtank.payments.coinbase.models.Transaction.java

License:Apache License

public static Transaction fromJson(JsonObject json) {
    String id = json.get("id").getAsString();
    String createdAt = json.get("created_at").getAsString();
    Amount amount = Amount.fromJson(json.getAsJsonObject("amount"));
    boolean request = json.get("request").getAsBoolean();
    TransactionStatus status = TransactionStatus.valueOf(json.get("status").getAsString().toUpperCase());
    User sender = User.fromJson(json.getAsJsonObject("sender"));

    return json.has("recipient_address")
            ? new Transaction(id, createdAt, amount, request, status, sender,
                    json.get("recipient_address").getAsString())
            : new Transaction(id, createdAt, amount, request, status, sender,
                    User.fromJson(json.getAsJsonObject("recipient")));
}

From source file:com.cyanogenmod.account.gcm.model.MessageTypeAdapterFactory.java

License:Apache License

@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
    if (!Message.class.isAssignableFrom(type.getRawType())) {
        return null;
    }//from w w w  . j ava2s.  c  o  m

    final TypeAdapter<Message> rootAdapter = gson.getDelegateAdapter(this, TypeToken.get(Message.class));
    final TypeAdapter<PublicKeyMessage> keyExchangeAdapter = gson.getDelegateAdapter(this,
            TypeToken.get(PublicKeyMessage.class));
    final TypeAdapter<SymmetricKeyMessage> symmetricKeyAdapter = gson.getDelegateAdapter(this,
            TypeToken.get(SymmetricKeyMessage.class));
    final TypeAdapter<EncryptedMessage> secureMessageAdapter = gson.getDelegateAdapter(this,
            TypeToken.get(EncryptedMessage.class));
    final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);

    TypeAdapter<Message> result = new TypeAdapter<Message>() {
        @Override
        public void write(JsonWriter out, Message value) throws IOException {
            if (value instanceof PublicKeyMessage) {
                keyExchangeAdapter.write(out, (PublicKeyMessage) value);
            } else if (value instanceof SymmetricKeyMessage) {
                symmetricKeyAdapter.write(out, (SymmetricKeyMessage) value);
            } else if (value instanceof EncryptedMessage) {
                secureMessageAdapter.write(out, (EncryptedMessage) value);
            } else {
                JsonObject object = rootAdapter.toJsonTree(value).getAsJsonObject();
                elementAdapter.write(out, object);
            }
        }

        @Override
        public Message read(JsonReader in) throws IOException {
            JsonObject object = elementAdapter.read(in).getAsJsonObject();
            if (object.has("public_key")) {
                return keyExchangeAdapter.fromJsonTree(object);
            } else if (object.has("symmetric_key")) {
                return symmetricKeyAdapter.fromJsonTree(object);
            } else if (object.has("ciphertext")) {
                return secureMessageAdapter.fromJsonTree(object);
            } else {
                return rootAdapter.fromJsonTree(object);
            }
        }
    }.nullSafe();

    return (TypeAdapter<T>) result;
}

From source file:com.datascience.gal.DawidSkeneDeserializer.java

License:Open Source License

@Override
public DawidSkene deserialize(JsonElement json, Type type, JsonDeserializationContext context)
        throws JsonParseException {
    JsonObject jobject = (JsonObject) json;
    if (jobject.has("dsmethod"))
        return incrementalDeserializer.deserialize(json, type, context);
    else/*from  w ww  . ja va 2  s  .c  o m*/
        return batchDeserializer.deserialize(json, type, context);
}

From source file:com.datascience.serialization.json.JSONUtils.java

License:Open Source License

public static void ensureDefaultString(JsonObject params, String paramName, String paramValue) {
    if (!params.has(paramName)) {
        params.addProperty(paramName, paramValue);
    }/*from   w  w  w .j  a  va  2  s  . c o  m*/
}

From source file:com.datascience.serialization.json.JSONUtils.java

License:Open Source License

public static void ensureDefaultNumber(JsonObject params, String paramName, Number paramValue) {
    if (!params.has(paramName)) {
        params.addProperty(paramName, paramValue);
    }//from   w  ww  .ja va2  s  . c o m
}

From source file:com.datascience.serialization.json.JSONUtils.java

License:Open Source License

public static String getDefaultString(JsonObject params, String paramName, String defaultVal) {
    return params.has(paramName) ? params.get(paramName).getAsString() : defaultVal;
}

From source file:com.denimgroup.threadfix.cli.util.JsonTestUtils.java

License:Mozilla Public License

private static void innerValidate(JsonObject jsonObject, String[] fields) {
    assert jsonObject != null : "Null object passed to innerValidate. Fix the code.";

    Set<String> missingFields = new HashSet<String>();
    for (String field : fields) {
        if (!jsonObject.has(field)) {
            missingFields.add(field);// ww w .ja  v  a2  s . c  o m
        }
    }

    assert missingFields.isEmpty() : "JsonObject " + jsonObject + " was missing " + missingFields;

    if (jsonObject.entrySet().size() != fields.length) {
        Set<String> actualFields = new HashSet<String>();
        for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
            actualFields.add(entry.getKey());
        }
        actualFields.removeAll(Arrays.asList(fields));
        assert actualFields.isEmpty() : "The returned JSON had the extra fields : " + actualFields;
    }

}

From source file:com.drakeet.rebase.api.tool.ResponseTypeAdapterFactory.java

License:Open Source License

@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
    final TypeAdapter<T> delegateAdapter = gson.getDelegateAdapter(this, type);
    final TypeAdapter<JsonElement> jsonElementAdapter = gson.getAdapter(JsonElement.class);

    return new TypeAdapter<T>() {
        @Override// w w  w  .  j  ava 2s  . c om
        public void write(JsonWriter out, T value) throws IOException {
            delegateAdapter.write(out, value);
        }

        @Override
        @SuppressWarnings("PointlessBooleanExpression")
        public T read(JsonReader in) throws IOException {
            JsonElement jsonElement = jsonElementAdapter.read(in);
            if (jsonElement.isJsonObject()) {
                JsonObject jsonObject = jsonElement.getAsJsonObject();
                if (jsonObject.has(ERROR) && jsonObject.get(ERROR).getAsBoolean() == false) {
                    if (jsonObject.has(DATA) && isJson(jsonObject, DATA)) {
                        jsonElement = jsonObject.get(DATA);
                    }
                }
            }
            return delegateAdapter.fromJsonTree(jsonElement);
        }
    }.nullSafe();
}