Search in sources :

Example 96 with JsonValue

use of com.eclipsesource.json.JsonValue in project box-java-sdk by box.

the class BoxGroup method getCollaborations.

/**
 * Gets information about all of the collaborations for this group.
 *
 * @return a collection of information about the collaborations for this group.
 */
public Collection<BoxCollaboration.Info> getCollaborations() {
    BoxAPIConnection api = this.getAPI();
    URL url = COLLABORATIONS_URL_TEMPLATE.build(api.getBaseURL(), this.getID());
    BoxAPIRequest request = new BoxAPIRequest(api, url, "GET");
    BoxJSONResponse response = (BoxJSONResponse) request.send();
    JsonObject responseJSON = Json.parse(response.getJSON()).asObject();
    int entriesCount = responseJSON.get("total_count").asInt();
    Collection<BoxCollaboration.Info> collaborations = new ArrayList<>(entriesCount);
    JsonArray entries = responseJSON.get("entries").asArray();
    for (JsonValue entry : entries) {
        JsonObject entryObject = entry.asObject();
        BoxCollaboration collaboration = new BoxCollaboration(api, entryObject.get("id").asString());
        BoxCollaboration.Info info = collaboration.new Info(entryObject);
        collaborations.add(info);
    }
    return collaborations;
}
Also used : ArrayList(java.util.ArrayList) JsonValue(com.eclipsesource.json.JsonValue) JsonObject(com.eclipsesource.json.JsonObject) URL(java.net.URL) JsonArray(com.eclipsesource.json.JsonArray)

Example 97 with JsonValue

use of com.eclipsesource.json.JsonValue in project box-java-sdk by box.

the class BoxUser method getEmailAliases.

/**
 * Gets a collection of all the email aliases for this user.
 *
 * <p>Note that the user's primary login email is not included in the collection of email aliases.</p>
 *
 * @return a collection of all the email aliases for this user.
 */
public Collection<EmailAlias> getEmailAliases() {
    URL url = EMAIL_ALIASES_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID());
    BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET");
    BoxJSONResponse response = (BoxJSONResponse) request.send();
    JsonObject responseJSON = Json.parse(response.getJSON()).asObject();
    int totalCount = responseJSON.get("total_count").asInt();
    Collection<EmailAlias> emailAliases = new ArrayList<>(totalCount);
    JsonArray entries = responseJSON.get("entries").asArray();
    for (JsonValue value : entries) {
        JsonObject emailAliasJSON = value.asObject();
        emailAliases.add(new EmailAlias(emailAliasJSON));
    }
    return emailAliases;
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) ArrayList(java.util.ArrayList) JsonValue(com.eclipsesource.json.JsonValue) JsonObject(com.eclipsesource.json.JsonObject) URL(java.net.URL)

Example 98 with JsonValue

use of com.eclipsesource.json.JsonValue in project hazelcast by hazelcast.

the class JsonUtil method getObject.

/**
     * Returns a field in a Json object as an object.
     * Throws IllegalArgumentException if the field value is null.
     *
     * @param object the Json object
     * @param field the field in the Json object to return
     * @return the Json field value as a Json object
     */
public static JsonObject getObject(JsonObject object, String field) {
    final JsonValue value = object.get(field);
    throwExceptionIfNull(value, field);
    return value.asObject();
}
Also used : JsonValue(com.eclipsesource.json.JsonValue)

Example 99 with JsonValue

use of com.eclipsesource.json.JsonValue in project hazelcast by hazelcast.

the class JsonUtil method getString.

/**
     * Returns a field in a Json object as a string.
     * Throws IllegalArgumentException if the field value is null.
     *
     * @param object the Json Object
     * @param field the field in the Json object to return
     * @return the Json field value as a string
     */
public static String getString(JsonObject object, String field) {
    final JsonValue value = object.get(field);
    throwExceptionIfNull(value, field);
    return value.asString();
}
Also used : JsonValue(com.eclipsesource.json.JsonValue)

Example 100 with JsonValue

use of com.eclipsesource.json.JsonValue in project hazelcast by hazelcast.

the class LocalOperationStatsImpl method fromJson.

@Override
public void fromJson(JsonObject json) {
    maxVisibleSlowOperationCount = getLong(json, "maxVisibleSlowOperationCount", Long.MAX_VALUE);
    for (JsonValue jsonValue : getArray(json, "slowOperations")) {
        SlowOperationDTO slowOperationDTO = new SlowOperationDTO();
        slowOperationDTO.fromJson(jsonValue.asObject());
        slowOperations.add(slowOperationDTO);
    }
    creationTime = getLong(json, "creationTime", -1L);
}
Also used : JsonValue(com.eclipsesource.json.JsonValue) SlowOperationDTO(com.hazelcast.internal.management.dto.SlowOperationDTO)

Aggregations

JsonValue (com.eclipsesource.json.JsonValue)147 JsonObject (com.eclipsesource.json.JsonObject)74 JsonArray (com.eclipsesource.json.JsonArray)43 Test (org.junit.Test)38 ArrayList (java.util.ArrayList)26 URL (java.net.URL)21 HashMap (java.util.HashMap)10 IOException (java.io.IOException)9 Member (com.eclipsesource.json.JsonObject.Member)6 ParseException (com.eclipsesource.json.ParseException)4 File (java.io.File)4 MalformedURLException (java.net.MalformedURLException)4 InetSocketAddress (java.net.InetSocketAddress)3 Collection (java.util.Collection)3 Map (java.util.Map)3 WebTarget (javax.ws.rs.client.WebTarget)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 JsonUtil.getString (com.hazelcast.util.JsonUtil.getString)2 WalletCallException (com.vaklinov.zcashui.ZCashClientCaller.WalletCallException)2 FileInputStream (java.io.FileInputStream)2