Java Code Examples for com.eclipsesource.json.JsonObject#getBoolean()

The following examples show how to use com.eclipsesource.json.JsonObject#getBoolean() . 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: MessagingOptions.java    From zencash-swing-wallet-ui with MIT License 5 votes vote down vote up
public void copyFromJSONObject(JsonObject obj)
	throws IOException
{
	// Mandatory fields!
	this.automaticallyAddUsersIfNotExplicitlyImported = 
		obj.getBoolean("automaticallyaddusersifnotexplicitlyimported", true);
	this.amountToSend   = obj.getDouble("amounttosend",   0.0001d);
	this.transactionFee = obj.getDouble("transactionfee", 0.0001d);
}
 
Example 2
Source File: Message.java    From zencash-swing-wallet-ui with MIT License 5 votes vote down vote up
public void copyFromJSONObject(JsonObject obj)
{
	// Wire protocol fields
	this.version       = obj.getInt("ver",              1);
	this.from          = obj.getString("from",          "");
	this.message       = obj.getString("message",       "");
	this.sign          = obj.getString("sign",          "");
	this.threadID      = obj.getString("threadid",      "");	
	this.returnAddress = obj.getString("returnaddress", "");
	
	// Additional fields - may be missing, get default values
	this.transactionID = obj.getString("transactionID", "");
	this.time          = new Date(obj.getLong("time",   0));
	this.direction     = DIRECTION_TYPE.valueOf(
			                 obj.getString("direction", DIRECTION_TYPE.RECEIVED.toString()));
	this.verification  = VERIFICATION_TYPE.valueOf(
			                 obj.getString("verification", VERIFICATION_TYPE.UNVERIFIED.toString()));
	
	if (obj.get("isanonymous") != null)
	{
		this.isAnonymous = obj.getBoolean("isanonymous", false);
	} else
	{
		// Determine from content if it is anonymous
		this.isAnonymous = obj.get("threadid") != null; 
	}
}
 
Example 3
Source File: ZCashClientCaller.java    From zencash-swing-wallet-ui with MIT License 5 votes vote down vote up
public synchronized boolean isWatchOnlyOrInvalidAddress(String address)
	throws WalletCallException, IOException, InterruptedException
{
	JsonObject response = this.executeCommandAndGetJsonValue("validateaddress", wrapStringParameter(address)).asObject();

	if (response.getBoolean("isvalid", false))
	{
		return response.getBoolean("iswatchonly", true);
	}
	
	return true;
}
 
Example 4
Source File: MessagingIdentity.java    From zencash-swing-wallet-ui with MIT License 4 votes vote down vote up
public void copyFromJSONObject(JsonObject obj)
	throws IOException
{
	// Mandatory fields!
	this.nickname           = obj.getString("nickname",           "");
	this.sendreceiveaddress = obj.getString("sendreceiveaddress", "");
	this.senderidaddress    = obj.getString("senderidaddress",    "");

	this.firstname          = obj.getString("firstname",          "");
	this.middlename         = obj.getString("middlename",         "");
	this.surname            = obj.getString("surname",            "");
	this.email              = obj.getString("email",              "");
	this.streetaddress      = obj.getString("streetaddress",      "");
	this.facebook           = obj.getString("facebook",           "");		
	this.twitter            = obj.getString("twitter",            "");	
	
	this.isAnonymous        = obj.getBoolean("isanonymous",       false);
	this.isGroup            = obj.getBoolean("isgroup",           false);
	this.threadID           = obj.getString("threadid",           "");	
	
	if (this.isGroup())
	{
		if (Util.stringIsEmpty(this.nickname) || Util.stringIsEmpty(this.sendreceiveaddress))
		{
			throw new IOException("Mandatory field is missing in creating group messaging identity!");
		}
	} else if (this.isAnonymous())
	{
		if (Util.stringIsEmpty(this.nickname) || Util.stringIsEmpty(this.threadID))
		{
			throw new IOException("Mandatory field is missing in creating anonymous messaging identity!");
		}			
	} else
	{
		// Make sure the mandatory fields are there
		if (Util.stringIsEmpty(this.nickname) || Util.stringIsEmpty(this.senderidaddress))
		{
			throw new IOException("Mandatory field is missing in creating messaging identity!");
		}
	}
}
 
Example 5
Source File: Configurable.java    From Recaf with MIT License 4 votes vote down vote up
/**
 * @param path
 * 		Path to json file of config.
 *
 * @throws IOException
 * 		When the file cannot be read.
 */
@SuppressWarnings({"unchecked", "rawtypes"})
default void load(Path path) throws IOException {
	JsonObject json = Json.parse(FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8)).asObject();
	for(FieldWrapper field : getConfigFields()) {
		String name = field.key();
		if(name == null)
			continue;
		final JsonValue value = json.get(name);
		if(value != null) {
			try {
				Class<?> type = field.type();
				if(type.equals(Boolean.TYPE))
					field.set(value.asBoolean());
				else if(type.equals(Integer.TYPE))
					field.set(value.asInt());
				else if(type.equals(Long.TYPE))
					field.set(value.asLong());
				else if(type.equals(Float.TYPE))
					field.set(value.asFloat());
				else if(type.equals(Double.TYPE))
					field.set(value.asDouble());
				else if(type.equals(String.class))
					field.set(value.asString());
				else if(type.isEnum())
					field.set(Enum.valueOf((Class<? extends Enum>) (Class<?>) field.type(), value.asString()));
				else if(type.equals(Resource.class)) {
					JsonObject object = value.asObject();
					String resPath = object.getString("path", null);
					if(object.getBoolean("internal", true))
						field.set(Resource.internal(resPath));
					else
						field.set(Resource.external(resPath));
				} else if(type.equals(List.class)) {
					List<Object> list = new ArrayList<>();
					JsonArray array = value.asArray();
					// We're gonna assume our lists just hold strings
					array.forEach(v -> {
						if(v.isString())
							list.add(v.asString());
						else
							warn("Didn't properly load config for {}, expected all string arguments", name);
					});
					field.set(list);
				} else if(supported(type))
					loadType(field, type, value);
				else
					warn("Didn't load config for {}, unsure how to serialize.", name);
			} catch(Exception ex) {
				error(ex, "Skipping bad option: {} - {}", path.getFileName(), name);
			}
		}
	}
	onLoad();
}