Java Code Examples for com.eclipsesource.json.JsonArray#toString()

The following examples show how to use com.eclipsesource.json.JsonArray#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZCashClientCaller.java    From zencash-swing-wallet-ui with MIT License 6 votes vote down vote up
public synchronized boolean isSendingOperationComplete(String opID)
    throws WalletCallException, IOException, InterruptedException
{
	JsonArray response = this.executeCommandAndGetJsonArray(
		"z_getoperationstatus", wrapStringParameter("[\"" + opID + "\"]"));
	JsonObject jsonStatus = response.get(0).asObject();

	String status = jsonStatus.getString("status", "ERROR");

	Log.info("Operation " + opID + " status is " + response + ".");

	if (status.equalsIgnoreCase("success") ||
		status.equalsIgnoreCase("error") ||
		status.equalsIgnoreCase("failed"))
	{
		return true;
	} else if (status.equalsIgnoreCase("executing") || status.equalsIgnoreCase("queued"))
	{
		return false;
	} else
	{
		throw new WalletCallException("Unexpected status response from wallet: " + response.toString());
	}
}
 
Example 2
Source File: ZCashClientCaller.java    From zencash-swing-wallet-ui with MIT License 6 votes vote down vote up
public synchronized boolean isCompletedOperationSuccessful(String opID)
    throws WalletCallException, IOException, InterruptedException
{
	JsonArray response = this.executeCommandAndGetJsonArray(
		"z_getoperationstatus", wrapStringParameter("[\"" + opID + "\"]"));
	JsonObject jsonStatus = response.get(0).asObject();

	String status = jsonStatus.getString("status", "ERROR");

	Log.info("Operation " + opID + " status is " + response + ".");

	if (status.equalsIgnoreCase("success"))
	{
		return true;
	} else if (status.equalsIgnoreCase("error") || status.equalsIgnoreCase("failed"))
	{
		return false;
	} else
	{
		throw new WalletCallException("Unexpected final operation status response from wallet: " + response.toString());
	}
}
 
Example 3
Source File: BoxArray.java    From box-android-sdk with Apache License 2.0 5 votes vote down vote up
public String toJson() {
    JsonArray array = new JsonArray();
    for (int i = 0; i < size(); i++) {
        array.add(get(i).toJsonObject());
    }
    return array.toString();
}
 
Example 4
Source File: ZCashClientCaller.java    From zencash-swing-wallet-ui with MIT License 4 votes vote down vote up
public synchronized String sendMessage(String from, String to, double amount, double fee, String memo)
	throws WalletCallException, IOException, InterruptedException
{
	String hexMemo = Util.encodeHexString(memo);
	JsonObject toArgument = new JsonObject();
	toArgument.set("address", to);
	if (hexMemo.length() >= 2)
	{
		toArgument.set("memo", hexMemo.toString());
	}
	
	DecimalFormatSymbols decSymbols = new DecimalFormatSymbols(Locale.ROOT);

	// TODO: The JSON Builder has a problem with double values that have no fractional part
	// it serializes them as integers that ZCash does not accept. This will work with the 
	// fractional amounts always used for messaging
	toArgument.set("amount", new DecimalFormat("########0.00######", decSymbols).format(amount));

	JsonArray toMany = new JsonArray();
	toMany.add(toArgument);
	
	String toManyArrayStr =	toMany.toString();		
	String[] sendCashParameters = new String[]
    {
	    this.zcashcli.getCanonicalPath(), "z_sendmany", wrapStringParameter(from),
	    wrapStringParameter(toManyArrayStr),
	    // Default min confirmations for the input transactions is 1
	    "1",
	    // transaction fee
	    new DecimalFormat("########0.00######", decSymbols).format(fee)
	};
			
	// Create caller to send cash
    CommandExecutor caller = new CommandExecutor(sendCashParameters);
    String strResponse = caller.execute();

	if (strResponse.trim().toLowerCase(Locale.ROOT).startsWith("error:") ||
		strResponse.trim().toLowerCase(Locale.ROOT).startsWith("error code:"))
	{
	  	throw new WalletCallException("Error response from wallet: " + strResponse);
	}

	Log.info("Sending cash message with the following command: " +
               sendCashParameters[0] + " " + sendCashParameters[1] + " " +
               sendCashParameters[2] + " " + sendCashParameters[3] + " " +
               sendCashParameters[4] + " " + sendCashParameters[5] + "." +
               " Got result: [" + strResponse + "]");

	return strResponse.trim();
}
 
Example 5
Source File: LimitRuleJsonSerialiser.java    From ratelimitj with Apache License 2.0 4 votes vote down vote up
String encode(Iterable<RequestLimitRule> rules) {
    JsonArray jsonArray = Json.array().asArray();
    rules.forEach(rule -> jsonArray.add(toJsonArray(rule)));
    return jsonArray.toString();
}