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

The following examples show how to use com.eclipsesource.json.JsonValue#asString() . 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: BoxCollaborator.java    From box-java-sdk with Apache License 2.0 6 votes vote down vote up
@Override
protected void parseJSONMember(JsonObject.Member member) {
    super.parseJSONMember(member);
    JsonValue value = member.getValue();
    String name = member.getName();

    try {

        if (name.equals("name")) {
            this.name = value.asString();
        } else if (name.equals("created_at")) {
            this.createdAt = BoxDateFormat.parse(value.asString());
        } else if (name.equals("modified_at")) {
            this.modifiedAt = BoxDateFormat.parse(value.asString());
        } else if (name.equals("login")) {
            this.login = value.asString();
        }
    } catch (Exception e) {
        throw new BoxDeserializationException(name, value.toString(), e);
    }
}
 
Example 2
Source File: BoxClassification.java    From box-java-sdk with Apache License 2.0 6 votes vote down vote up
@Override
protected void parseJSONMember(JsonObject.Member member) {
    super.parseJSONMember(member);

    String memberName = member.getName();
    JsonValue value = member.getValue();

    try {
        if (memberName.equals("color")) {
            this.color = value.asString();
        } else if (memberName.equals("definition")) {
            this.definition = value.asString();
        } else if (memberName.equals("name")) {
            this.name = value.asString();
        }
    } catch (Exception e) {
        throw new BoxDeserializationException(memberName, value.toString(), e);
    }
}
 
Example 3
Source File: BoxEntity.java    From box-android-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method that will parse into a known child of BoxEntity.
 *
 * @param json JsonObject representing a BoxEntity or one of its known children.
 * @return a BoxEntity or one of its known children.
 */
public static BoxEntity createEntityFromJson(final JsonObject json){
    JsonValue typeValue = json.get(BoxEntity.FIELD_TYPE);
    if (!typeValue.isString()) {
        return null;
    }
    String type = typeValue.asString();
    BoxEntityCreator creator = ENTITY_ADDON_MAP.get(type);
    BoxEntity entity = null;
    if (creator == null){
        entity = new BoxEntity();
    } else {
        entity = creator.createEntity();
    }
    entity.createFromJson(json);
    return entity;
}
 
Example 4
Source File: BoxGroup.java    From box-java-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void parseJSONMember(JsonObject.Member member) {
    super.parseJSONMember(member);

    String memberName = member.getName();
    JsonValue value = member.getValue();
    try {
        if (memberName.equals("description")) {
            this.description = value.asString();
        } else if (memberName.equals("external_sync_identifier")) {
            this.externalSyncIdentifier = value.asString();
        } else if (memberName.equals("invitability_level")) {
            this.invitabilityLevel = value.asString();
        } else if (memberName.equals("member_viewability_level")) {
            this.memberViewabilityLevel = value.asString();
        } else if (memberName.equals("provenance")) {
            this.provenance = value.asString();
        }
    } catch (Exception e) {
        throw new BoxDeserializationException(memberName, value.toString(), e);
    }
}
 
Example 5
Source File: MetadataTemplate.java    From box-java-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
void parseJSONMember(JsonObject.Member member) {
    JsonValue value = member.getValue();
    String memberName = member.getName();
    if (memberName.equals("type")) {
        this.type = value.asString();
    } else if (memberName.equals("key")) {
        this.key = value.asString();
    } else if (memberName.equals("displayName")) {
        this.displayName = value.asString();
    } else if (memberName.equals("hidden")) {
        this.isHidden = value.asBoolean();
    } else if (memberName.equals("description")) {
        this.description = value.asString();
    } else if (memberName.equals("options")) {
        this.options = new ArrayList<Option>();
        for (JsonValue option : value.asArray()) {
            this.options.add(new Option(option.asObject()));
        }
    } else if (memberName.equals("id")) {
        this.id = value.asString();
    }
}
 
Example 6
Source File: EmailAlias.java    From box-java-sdk with Apache License 2.0 6 votes vote down vote up
@Override
void parseJSONMember(JsonObject.Member member) {
    JsonValue value = member.getValue();
    String memberName = member.getName();
    try {
        if (memberName.equals("id")) {
            this.id = value.asString();
        } else if (memberName.equals("is_confirmed")) {
            this.isConfirmed = value.asBoolean();
        } else if (memberName.equals("email")) {
            this.email = value.asString();
        }
    } catch (Exception e) {
        throw new BoxDeserializationException(memberName, value.toString(), e);
    }
}
 
Example 7
Source File: ItemJson.java    From Cubes with MIT License 5 votes vote down vote up
public static void addItem(JsonObject json) {
  if (json.get("tool") != null) {
    addItemTool(json);
    return;
  }
  String id = json.getString("id", null);
  if (id == null) throw new JsonException("No item id");
  JItem item = new JItem(id);

  JsonValue prop;

  prop = json.get("texture");
  if (prop != null) {
    item.textureString = prop.asString();
  } else {
    item.textureString = id;
  }

  for (JsonObject.Member member : json) {
    switch (member.getName()) {
      case "id":
      case "texture":
        break;
      default:
        throw new JsonException("Unexpected block member \"" + member.getName() + "\"");
    }
  }

  IDManager.register(item);
}
 
Example 8
Source File: BoxTask.java    From box-java-sdk with Apache License 2.0 5 votes vote down vote up
@Override
void parseJSONMember(JsonObject.Member member) {
    super.parseJSONMember(member);

    String memberName = member.getName();
    JsonValue value = member.getValue();
    try {
        if (memberName.equals("item")) {
            JsonObject itemJSON = value.asObject();
            String itemID = itemJSON.get("id").asString();
            BoxFile file = new BoxFile(getAPI(), itemID);
            this.item = file.new Info(itemJSON);
        } else if (memberName.equals("due_at")) {
            this.dueAt = BoxDateFormat.parse(value.asString());
        } else if (memberName.equals("action")) {
            this.action = value.asString();
        } else if (memberName.equals("completion_rule")) {
            this.completionRule = value.asString();
        } else if (memberName.equals("message")) {
            this.message = value.asString();
        } else if (memberName.equals("task_assignment_collection")) {
            this.taskAssignments = this.parseTaskAssignmentCollection(value.asObject());
        } else if (memberName.equals("is_completed")) {
            this.completed = value.asBoolean();
        } else if (memberName.equals("created_by")) {
            JsonObject userJSON = value.asObject();
            String userID = userJSON.get("id").asString();
            BoxUser user = new BoxUser(getAPI(), userID);
            this.createdBy = user.new Info(userJSON);
        } else if (memberName.equals("created_at")) {
            this.createdAt = BoxDateFormat.parse(value.asString());
        }

    } catch (Exception e) {
        throw new BoxDeserializationException(memberName, value.toString(), e);
    }
}
 
Example 9
Source File: BoxCollaborationWhitelist.java    From box-java-sdk with Apache License 2.0 5 votes vote down vote up
@Override
protected void parseJSONMember(JsonObject.Member member) {
    super.parseJSONMember(member);

    String memberName = member.getName();
    JsonValue value = member.getValue();
    try {
        if (memberName.equals("domain")) {
            this.domain = value.asString();

        } else if (memberName.equals("type")) {
            this.type = value.asString();

        } else if (memberName.equals("direction")) {
            this.direction = WhitelistDirection.fromDirection(value.asString());

        } else if (memberName.equals("enterprise")) {
            JsonObject jsonObject = value.asObject();
            this.enterprise = new BoxEnterprise(jsonObject);

        } else if (memberName.equals("created_at")) {
            this.createdAt = BoxDateFormat.parse(value.asString());

        } else if (memberName.equals("modified_at")) {
            this.modifiedAt = BoxDateFormat.parse(value.asString());

        }
    } catch (Exception e) {
        throw new BoxDeserializationException(memberName, value.toString(), e);
    }
}
 
Example 10
Source File: BoxSharedLink.java    From box-java-sdk with Apache License 2.0 5 votes vote down vote up
@Override
void parseJSONMember(JsonObject.Member member) {
    JsonValue value = member.getValue();
    String memberName = member.getName();

    try {
        if (memberName.equals("url")) {
            this.url = value.asString();
        } else if (memberName.equals("download_url")) {
            this.downloadUrl = value.asString();
        } else if (memberName.equals("vanity_url")) {
            this.vanityUrl = value.asString();
        } else if (memberName.equals("is_password_enabled")) {
            this.isPasswordEnabled = value.asBoolean();
        } else if (memberName.equals("unshared_at")) {
            this.unsharedAt = BoxDateFormat.parse(value.asString());
        } else if (memberName.equals("download_count")) {
            this.downloadCount = Double.valueOf(value.toString()).longValue();
        } else if (memberName.equals("preview_count")) {
            this.previewCount = Double.valueOf(value.toString()).longValue();
        } else if (memberName.equals("access")) {
            this.access = this.parseAccessValue(value);
        } else if (memberName.equals("effective_access")) {
            this.effectiveAccess = this.parseAccessValue(value);
        } else if (memberName.equals("permissions")) {
            if (this.permissions == null) {
                this.setPermissions(new Permissions(value.asObject()));
            } else {
                this.permissions.update(value.asObject());
            }
        }
    } catch (Exception e) {
        throw new BoxDeserializationException(memberName, value.toString(), e);
    }
}
 
Example 11
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 12
Source File: NameFactory.java    From dungeon with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Reads the value for "plural", if present, or generates the plural value by appending 's' to the singular form.
 *
 * <p>If the plural form is present and happens to be identical to what would be generated by appending 's' to the
 * singular form, a warning is logged about unnecessary data.
 */
private static String readOrRenderPlural(@NotNull JsonObject jsonObject, String singular) {
  JsonValue value = jsonObject.get("plural");
  if (value == null) {
    return singular + 's';
  } else {
    String plural = value.asString();
    warnIfPluralIsUnnecessary(singular, plural);
    return plural;
  }
}
 
Example 13
Source File: BoxUploadEmail.java    From box-java-sdk with Apache License 2.0 5 votes vote down vote up
@Override
void parseJSONMember(JsonObject.Member member) {
    JsonValue value = member.getValue();
    String memberName = member.getName();
    try {
        if (memberName.equals("access")) {
            this.access = Access.fromJSONValue(value.asString());
        } else if (memberName.equals("email")) {
            this.email = value.asString();
        }
    } catch (Exception e) {
        throw new BoxDeserializationException(memberName, value.toString(), e);
    }
}
 
Example 14
Source File: BoxWebHook.java    From box-java-sdk with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
void parseJSONMember(JsonObject.Member member) {
    super.parseJSONMember(member);
    String memberName = member.getName();
    JsonValue value = member.getValue();
    try {
        if (memberName.equals(JSON_KEY_TARGET)) {
            String targetType = value.asObject().get(JSON_KEY_TARGET_TYPE).asString();
            String targetId = value.asObject().get(JSON_KEY_TARGET_ID).asString();
            this.target = new Target(targetType, targetId);
        } else if (memberName.equals(JSON_KEY_TRIGGERS)) {
            this.triggers = new HashSet<Trigger>(
                    CollectionUtils.map(value.asArray().values(), JSON_VALUE_TO_TRIGGER)
            );
        } else if (memberName.equals(JSON_KEY_ADDRESS)) {
            this.address = new URL(value.asString());
        } else if (memberName.equals(JSON_KEY_CREATED_BY)) {
            JsonObject userJSON = value.asObject();
            if (this.createdBy == null) {
                String userID = userJSON.get(JSON_KEY_ID).asString();
                BoxUser user = new BoxUser(getAPI(), userID);
                this.createdBy = user.new Info(userJSON);
            } else {
                this.createdBy.update(userJSON);
            }
        } else if (memberName.equals("created_at")) {
            this.createdAt = BoxDateFormat.parse(value.asString());
        }
    } catch (Exception e) {
        throw new BoxDeserializationException(memberName, value.toString(), e);
    }
}
 
Example 15
Source File: JsonCreaturePresetFactory.java    From dungeon with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Attempts to read a string from the provided JSON object, returning null if the string is not present or if the
 * value is not a string.
 *
 * @param jsonObject a JsonObject, not null
 * @param name a String, not null
 * @return a String or null
 */
@Nullable
private static String getStringFromJsonObject(@NotNull JsonObject jsonObject, @NotNull String name) {
  JsonValue value = jsonObject.get(name);
  if (value == null || !value.isString()) {
    return null;
  } else {
    return value.asString();
  }
}
 
Example 16
Source File: StringSetting.java    From Cubes with MIT License 4 votes vote down vote up
@Override
public void readJson(JsonValue json) {
  String str = json.asString();
  if (str != null) this.s = str;
  onChange();
}
 
Example 17
Source File: BoxCollaboration.java    From box-java-sdk with Apache License 2.0 4 votes vote down vote up
@Override
protected void parseJSONMember(JsonObject.Member member) {
    super.parseJSONMember(member);

    String memberName = member.getName();
    JsonValue value = member.getValue();
    try {
        if (memberName.equals("created_by")) {
            JsonObject userJSON = value.asObject();
            if (this.createdBy == null) {
                String userID = userJSON.get("id").asString();
                BoxUser user = new BoxUser(getAPI(), userID);
                this.createdBy = user.new Info(userJSON);
            } else {
                this.createdBy.update(userJSON);
            }

        } else if (memberName.equals("created_at")) {
            this.createdAt = BoxDateFormat.parse(value.asString());

        } else if (memberName.equals("modified_at")) {
            this.modifiedAt = BoxDateFormat.parse(value.asString());

        } else if (memberName.equals("expires_at")) {
            this.expiresAt = BoxDateFormat.parse(value.asString());

        } else if (memberName.equals("status")) {
            String statusString = value.asString().toUpperCase();
            this.status = Status.valueOf(statusString);

        } else if (memberName.equals("accessible_by")) {
            JsonObject accessibleByJSON = value.asObject();
            if (this.accessibleBy == null) {
                this.accessibleBy = this.parseAccessibleBy(accessibleByJSON);
            } else {
                this.updateAccessibleBy(accessibleByJSON);
            }
        } else if (memberName.equals("role")) {
            this.role = Role.fromJSONString(value.asString());

        } else if (memberName.equals("acknowledged_at")) {
            this.acknowledgedAt = BoxDateFormat.parse(value.asString());

        } else if (memberName.equals("can_view_path")) {
            this.canViewPath = value.asBoolean();

        } else if (memberName.equals("invite_email")) {
            this.inviteEmail = value.asString();

        } else if (memberName.equals("item")) {
            JsonObject folderJSON = value.asObject();
            if (this.item == null) {
                String folderID = folderJSON.get("id").asString();
                BoxFolder folder = new BoxFolder(getAPI(), folderID);
                this.item = folder.new Info(folderJSON);
            } else {
                this.item.update(folderJSON);
            }
        }
    } catch (Exception e) {
        throw new BoxDeserializationException(memberName, value.toString(), e);
    }
}
 
Example 18
Source File: BoxUser.java    From box-java-sdk with Apache License 2.0 4 votes vote down vote up
@Override
protected void parseJSONMember(JsonObject.Member member) {
    super.parseJSONMember(member);

    JsonValue value = member.getValue();
    String memberName = member.getName();
    try {
        if (memberName.equals("login")) {
            this.login = value.asString();
        } else if (memberName.equals("role")) {
            this.role = Role.fromJSONValue(value.asString());
        } else if (memberName.equals("language")) {
            this.language = value.asString();
        } else if (memberName.equals("timezone")) {
            this.timezone = value.asString();
        } else if (memberName.equals("space_amount")) {
            this.spaceAmount = Double.valueOf(value.toString()).longValue();
        } else if (memberName.equals("space_used")) {
            this.spaceUsed = Double.valueOf(value.toString()).longValue();
        } else if (memberName.equals("max_upload_size")) {
            this.maxUploadSize = Double.valueOf(value.toString()).longValue();
        } else if (memberName.equals("status")) {
            this.status = Status.fromJSONValue(value.asString());
        } else if (memberName.equals("job_title")) {
            this.jobTitle = value.asString();
        } else if (memberName.equals("phone")) {
            this.phone = value.asString();
        } else if (memberName.equals("address")) {
            this.address = value.asString();
        } else if (memberName.equals("avatar_url")) {
            this.avatarURL = value.asString();
        } else if (memberName.equals("can_see_managed_users")) {
            this.canSeeManagedUsers = value.asBoolean();
        } else if (memberName.equals("is_sync_enabled")) {
            this.isSyncEnabled = value.asBoolean();
        } else if (memberName.equals("is_external_collab_restricted")) {
            this.isExternalCollabRestricted = value.asBoolean();
        } else if (memberName.equals("is_exempt_from_device_limits")) {
            this.isExemptFromDeviceLimits = value.asBoolean();
        } else if (memberName.equals("is_exempt_from_login_verification")) {
            this.isExemptFromLoginVerification = value.asBoolean();
        } else if (memberName.equals("is_password_reset_required")) {
            this.isPasswordResetRequired = value.asBoolean();
        } else if (memberName.equals("is_platform_access_only")) {
            this.isPlatformAccessOnly = value.asBoolean();
        } else if (memberName.equals("external_app_user_id")) {
            this.externalAppUserId = value.asString();
        } else if (memberName.equals("enterprise")) {
            JsonObject jsonObject = value.asObject();
            if (this.enterprise == null) {
                this.enterprise = new BoxEnterprise(jsonObject);
            } else {
                this.enterprise.update(jsonObject);
            }
        } else if (memberName.equals("my_tags")) {
            this.myTags = this.parseMyTags(value.asArray());
        } else if (memberName.equals("hostname")) {
            this.hostname = value.asString();
        } else if (memberName.equals("tracking_codes")) {
            this.trackingCodes = this.parseTrackingCodes(value.asArray());
        }
    } catch (Exception e) {
        throw new BoxDeserializationException(memberName, value.toString(), e);
    }

}
 
Example 19
Source File: IrdbImporter.java    From IrScrutinizer with GNU General Public License v3.0 4 votes vote down vote up
public ProtocolDeviceSubdevice(JsonValue jprotocol, long device, long subdevice) {
    this(jprotocol.isString() ? jprotocol.asString() : null, device, subdevice);
}
 
Example 20
Source File: FractionList.java    From wildfly-swarm with Apache License 2.0 4 votes vote down vote up
private String toString(JsonValue jsonValue) {
    return jsonValue.isNull() ? null : jsonValue.asString();
}