Search in sources :

Example 76 with JsonValue

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

the class BoxZipConflictItem method parseJSONMember.

@Override
void parseJSONMember(JsonObject.Member member) {
    JsonValue value = member.getValue();
    String memberName = member.getName();
    if (memberName.equals("id")) {
        this.id = value.asString();
    } else if (memberName.equals("type")) {
        this.type = value.asString();
    } else if (memberName.equals("original_name")) {
        this.originalName = value.asString();
    } else if (memberName.equals("download_name")) {
        this.downloadName = value.asString();
    }
}
Also used : JsonValue(com.eclipsesource.json.JsonValue)

Example 77 with JsonValue

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

the class BoxZipInfo method parseJSONMember.

@Override
void parseJSONMember(JsonObject.Member member) {
    JsonValue value = member.getValue();
    String memberName = member.getName();
    try {
        if (memberName.equals("download_url")) {
            try {
                String urlString = value.asString();
                this.downloadURL = new URL(urlString);
            } catch (MalformedURLException e) {
                throw new BoxAPIException("Couldn't parse download url for zip", e);
            }
        } else if (memberName.equals("status_url")) {
            try {
                String urlString = value.asString();
                this.statusURL = new URL(urlString);
            } catch (MalformedURLException e) {
                throw new BoxAPIException("Couldn't parse status url for zip", e);
            }
        } else if (memberName.equals("expires_at")) {
            this.expiresAt = BoxDateFormat.parse(value.asString());
        } else if (memberName.equals("name_conflicts")) {
            this.nameConflicts = this.parseNameConflicts(value.asArray());
        }
    } catch (Exception e) {
        throw new BoxDeserializationException(memberName, value.toString(), e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) JsonValue(com.eclipsesource.json.JsonValue) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException)

Example 78 with JsonValue

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

the class BoxZipInfo method parseNameConflicts.

private List<BoxZipConflict> parseNameConflicts(JsonArray jsonArray) {
    List<BoxZipConflict> nameConflicts = new ArrayList<BoxZipConflict>(jsonArray.size());
    for (JsonValue conflict : jsonArray) {
        // We create a "conflictObj"  with the arbitrary key name "conflict" in order to allow BoxZipConflict
        // to later parse the object to create `List<BoxZipConflictItem> items` (since it can't take in an array)
        JsonObject conflictObj = new JsonObject().add("conflict", conflict);
        nameConflicts.add(new BoxZipConflict(conflictObj));
    }
    return nameConflicts;
}
Also used : ArrayList(java.util.ArrayList) JsonValue(com.eclipsesource.json.JsonValue) JsonObject(com.eclipsesource.json.JsonObject)

Example 79 with JsonValue

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

the class BatchAPIRequestTest method testThatBodyHasAllRequiredFieldsInEachResponse.

@Test
public void testThatBodyHasAllRequiredFieldsInEachResponse() {
    final String anyClientID = "";
    final String anyClientSecret = "";
    final String anyAccessToken = "";
    final String anyRefreshToken = "";
    BoxAPIConnection api = new BoxAPIConnection(anyClientID, anyClientSecret, anyAccessToken, anyRefreshToken);
    List<BoxAPIRequest> requests = new ArrayList<>();
    // Get current user request
    URL getMeURL = BoxUser.GET_ME_URL.build(api.getBaseURL());
    BoxAPIRequest getMeRequest = new BoxAPIRequest(getMeURL, HttpMethod.GET);
    requests.add(getMeRequest);
    // Create App User Request
    URL createUserURL = BoxUser.USERS_URL_TEMPLATE.build(api.getBaseURL());
    BoxJSONRequest createAppUserRequest = new BoxJSONRequest(createUserURL, HttpMethod.POST);
    createAppUserRequest.setBody("{\"name\":\"some-name\"," + "\"is_platform_access_only\":true}");
    requests.add(createAppUserRequest);
    // Get Root Folder Request
    URL getRootFolderURL = BoxFolder.FOLDER_INFO_URL_TEMPLATE.build(api.getBaseURL(), 0);
    BoxAPIRequest getRootFolderRequest = new BoxAPIRequest(getRootFolderURL, HttpMethod.GET);
    requests.add(getRootFolderRequest);
    BatchAPIRequest batchRequest = new BatchAPIRequest(api);
    batchRequest.prepareRequest(requests);
    assertTrue("requests field should be an array", (batchRequest.getBodyAsJsonObject().get("requests").isArray()));
    JsonArray requestsArray = batchRequest.getBodyAsJsonObject().get("requests").asArray();
    for (JsonValue request : requestsArray) {
        assertTrue("each request should be an object", (request.isObject()));
        assertTrue("each request should have a relative_url that is string", (((JsonObject) request).get("relative_url").isString()));
        assertTrue("each request should have a method that is string", (((JsonObject) request).get("method").isString()));
        assertTrue("each request should have headers as object", (((JsonObject) request).get("headers").isObject()));
        if (((JsonObject) request).get("method").asString().equals(HttpMethod.POST)) {
            assertTrue("request should have body when method is POST", (((JsonObject) request).get("body").isObject()));
        }
    }
}
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) Test(org.junit.Test)

Example 80 with JsonValue

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

the class BoxZipConflict method parseJSONMember.

@Override
void parseJSONMember(JsonObject.Member member) {
    JsonArray value = member.getValue().asArray();
    List<BoxZipConflictItem> conflictItems = new ArrayList<BoxZipConflictItem>(value.size());
    for (JsonValue item : value) {
        conflictItems.add(new BoxZipConflictItem(item.asObject()));
    }
    this.items = conflictItems;
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) ArrayList(java.util.ArrayList) JsonValue(com.eclipsesource.json.JsonValue)

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