Java Code Examples for com.eclipsesource.json.JsonValue#isNull()

The following examples show how to use com.eclipsesource.json.JsonValue#isNull() . 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: FractionListParser.java    From thorntail with Apache License 2.0 6 votes vote down vote up
private FractionDescriptor getFractionDescriptor(JsonObject fraction) {
    String groupId = toString(fraction.get("groupId"));
    String artifactId = toString(fraction.get("artifactId"));
    String key = groupId + ":" + artifactId;
    FractionDescriptor descriptor = descriptors.get(key);
    if (descriptor == null) {
        String version = toString(fraction.get("version"));
        String name = toString(fraction.get("name"));
        String description = toString(fraction.get("description"));
        String tags = toString(fraction.get("tags"));
        boolean internal = toBoolean(fraction.get("internal"));

        JsonValue stabilityIndexJson = fraction.get("stabilityIndex");
        int stabilityIndex = stabilityIndexJson == null || stabilityIndexJson.isNull() ? FractionStability.UNSTABLE.ordinal() : stabilityIndexJson.asInt();
        FractionStability stability;
        if (stabilityIndex < 0 || stabilityIndex >= FractionStability.values().length) {
            stability = FractionStability.UNSTABLE;
        } else {
            stability = FractionStability.values()[stabilityIndex];
        }
        descriptor = new FractionDescriptor(groupId, artifactId, version, name, description, tags, internal, stability);
        descriptors.put(key, descriptor);
    }
    return descriptor;
}
 
Example 2
Source File: BoxJsonObject.java    From box-android-sdk with Apache License 2.0 5 votes vote down vote up
public String getAsString(final String field){
    JsonValue value = getAsJsonValue(field);
    if (value == null || value.isNull()) {
        return null;
    }
    return value.asString();
}
 
Example 3
Source File: BoxJsonObject.java    From box-android-sdk with Apache License 2.0 5 votes vote down vote up
public <T extends BoxJsonObject> T getAsJsonObject(BoxJsonObjectCreator<T> creator, final String field){
    if (mInternalCache.get(field) != null){
        return (T)mInternalCache.get(field);
    }
    JsonValue value = getAsJsonValue(field);

    if (value == null || value.isNull() || !value.isObject()) {
        return null;
    }
    T entity = creator.createFromJsonObject(value.asObject());
    mInternalCache.put(field, entity);
    return entity;
}
 
Example 4
Source File: BoxJsonObject.java    From box-android-sdk with Apache License 2.0 5 votes vote down vote up
public ArrayList<String> getAsStringArray(final String field){
    if (mInternalCache.get(field) != null){
        return (ArrayList<String>)mInternalCache.get(field);
    }
    JsonValue value = getAsJsonValue(field);
    if (value == null || value.isNull()) {
        return null;
    }
    ArrayList<String> strings = new ArrayList<String>(value.asArray().size());
    for (JsonValue member : value.asArray()){
        strings.add(member.asString());
    }
    mInternalCache.put(field, strings);
    return strings;
}
 
Example 5
Source File: BoxJsonObject.java    From box-android-sdk with Apache License 2.0 5 votes vote down vote up
public HashSet<String> getPropertyAsStringHashSet(String field) {
    if (mInternalCache.get(field) != null){
        return (HashSet<String>)mInternalCache.get(field);
    }
    JsonValue value = getAsJsonValue(field);
    if (value == null || value.isNull()) {
        return null;
    }
    HashSet<String> strings = new HashSet<String>(value.asArray().size());
    for (JsonValue member : value.asArray()){
        strings.add(member.asString());
    }
    mInternalCache.put(field, strings);
    return strings;
}
 
Example 6
Source File: BoxJsonObject.java    From box-android-sdk with Apache License 2.0 5 votes vote down vote up
public JsonArray getAsJsonArray(final String field){
    JsonValue value = getAsJsonValue(field);
    if (value == null || value.isNull()) {
        return null;
    }
    return value.asArray();
}
 
Example 7
Source File: BoxJsonObject.java    From box-android-sdk with Apache License 2.0 5 votes vote down vote up
public Long getAsLong(final String field){
    JsonValue value = getAsJsonValue(field);
    if (value == null || value.isNull()) {
        return null;
    }
    return value.asLong();
}
 
Example 8
Source File: BoxJsonObject.java    From box-android-sdk with Apache License 2.0 5 votes vote down vote up
public Integer getAsInt(final String field){
    JsonValue value = getAsJsonValue(field);
    if (value == null || value.isNull()) {
        return null;
    }
    return value.asInt();
}
 
Example 9
Source File: BoxJsonObject.java    From box-android-sdk with Apache License 2.0 5 votes vote down vote up
public Float getAsFloat(final String field){
    JsonValue value = getAsJsonValue(field);
    if (value == null || value.isNull()) {
        return null;
    }
    return value.asFloat();
}
 
Example 10
Source File: BoxJsonObject.java    From box-android-sdk with Apache License 2.0 5 votes vote down vote up
public Double getAsDouble(final String field){
    JsonValue value = getAsJsonValue(field);
    if (value == null || value.isNull()) {
        return null;
    }
    return value.asDouble();
}
 
Example 11
Source File: JsonConfig.java    From ServerSync with GNU General Public License v3.0 5 votes vote down vote up
private static int getInt(JsonObject root, String name) throws IOException {
    JsonValue jsv = root.get(name);
    if (jsv.isNull()) {
        throw new IOException(String.format("No %s value present in configuration file", name));
    }
    if (!jsv.isNumber()) {
        throw new IOException(String.format("Invalid value for %s, expected integer", name));
    }
    return jsv.asInt();
}
 
Example 12
Source File: WebServer.java    From r2cloud with Apache License 2.0 5 votes vote down vote up
public static String getString(JsonValue value, String name) {
	JsonValue field = ((JsonObject) value).get(name);
	if (field == null || field.isNull()) {
		return null;
	}
	if (!field.isString()) {
		return null;
	}
	return field.asString();
}
 
Example 13
Source File: BoxFolder.java    From box-java-sdk with Apache License 2.0 5 votes vote down vote up
private EnumSet<Permission> parsePermissions(JsonObject jsonObject) {
    EnumSet<Permission> permissions = EnumSet.noneOf(Permission.class);
    for (JsonObject.Member member : jsonObject) {
        JsonValue value = member.getValue();
        if (value.isNull() || !value.asBoolean()) {
            continue;
        }

        String memberName = member.getName();
        if (memberName.equals("can_download")) {
            permissions.add(Permission.CAN_DOWNLOAD);
        } else if (memberName.equals("can_upload")) {
            permissions.add(Permission.CAN_UPLOAD);
        } else if (memberName.equals("can_rename")) {
            permissions.add(Permission.CAN_RENAME);
        } else if (memberName.equals("can_delete")) {
            permissions.add(Permission.CAN_DELETE);
        } else if (memberName.equals("can_share")) {
            permissions.add(Permission.CAN_SHARE);
        } else if (memberName.equals("can_invite_collaborator")) {
            permissions.add(Permission.CAN_INVITE_COLLABORATOR);
        } else if (memberName.equals("can_set_share_access")) {
            permissions.add(Permission.CAN_SET_SHARE_ACCESS);
        }
    }

    return permissions;
}
 
Example 14
Source File: BoxFile.java    From box-java-sdk with Apache License 2.0 5 votes vote down vote up
private EnumSet<Permission> parsePermissions(JsonObject jsonObject) {
    EnumSet<Permission> permissions = EnumSet.noneOf(Permission.class);
    for (JsonObject.Member member : jsonObject) {
        JsonValue value = member.getValue();
        if (value.isNull() || !value.asBoolean()) {
            continue;
        }

        String memberName = member.getName();
        if (memberName.equals("can_download")) {
            permissions.add(Permission.CAN_DOWNLOAD);
        } else if (memberName.equals("can_upload")) {
            permissions.add(Permission.CAN_UPLOAD);
        } else if (memberName.equals("can_rename")) {
            permissions.add(Permission.CAN_RENAME);
        } else if (memberName.equals("can_delete")) {
            permissions.add(Permission.CAN_DELETE);
        } else if (memberName.equals("can_share")) {
            permissions.add(Permission.CAN_SHARE);
        } else if (memberName.equals("can_set_share_access")) {
            permissions.add(Permission.CAN_SET_SHARE_ACCESS);
        } else if (memberName.equals("can_preview")) {
            permissions.add(Permission.CAN_PREVIEW);
        } else if (memberName.equals("can_comment")) {
            permissions.add(Permission.CAN_COMMENT);
        }
    }

    return permissions;
}
 
Example 15
Source File: BoxBrowseFolderActivity.java    From box-android-browse-sdk with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    Intent intent = new Intent();
    BoxFolder curFolder = getCurrentFolder();
    if (curFolder != null) {
        JsonObject jsonObject = curFolder.toJsonObject();
        JsonValue obj = jsonObject.get(BoxFolder.FIELD_ITEM_COLLECTION);
        if (obj != null && !obj.isNull()) {
            obj.asObject().set(BoxIterator.FIELD_ENTRIES, new JsonArray());
        }
        intent.putExtra(EXTRA_BOX_FOLDER, new BoxFolder(jsonObject));
    }
    setResult(RESULT_OK, intent);
    finish();
}
 
Example 16
Source File: JsonConfig.java    From ServerSync with GNU General Public License v3.0 5 votes vote down vote up
private static String getString(JsonObject root, String name) throws IOException {
    JsonValue jsv = root.get(name);
    if (jsv.isNull()) {
        throw new IOException(String.format("No %s value present in configuration file", name));
    }
    if (!jsv.isString()) {
        throw new IOException(String.format("Invalid value for %s, expected string", name));
    }
    return jsv.asString();
}
 
Example 17
Source File: JsonConfig.java    From ServerSync with GNU General Public License v3.0 5 votes vote down vote up
private static JsonArray getArray(JsonObject root, String name) throws IOException {
    JsonValue jsv = root.get(name);
    if (jsv.isNull()) {
        throw new IOException(String.format("No %s value present in configuration file", name));
    }
    if (!jsv.isArray()) {
        throw new IOException(String.format("Invalid value for %s, expected array", name));
    }
    return jsv.asArray();
}
 
Example 18
Source File: WebServer.java    From r2cloud with Apache License 2.0 5 votes vote down vote up
public static Double getDouble(JsonValue value, String name) {
	JsonValue result = ((JsonObject) value).get(name);
	if (result == null || result.isNull()) {
		return null;
	}
	return result.asDouble();
}
 
Example 19
Source File: FractionListParser.java    From thorntail with Apache License 2.0 4 votes vote down vote up
private String toString(JsonValue jsonValue) {
    return jsonValue.isNull() ? null : jsonValue.asString();
}
 
Example 20
Source File: FractionList.java    From wildfly-swarm with Apache License 2.0 4 votes vote down vote up
private boolean toBoolean(JsonValue jsonValue) {
    return jsonValue.isNull() ? false : jsonValue.asBoolean();
}