Reputation: 13
I am working on BoxSDK Java and I am attempting to capture the response from BoxSearch. As shown in their sample code:
https://developer.box.com/guides/search/
I am unable to capture the JSON response from searchResults. If I print this as toString it will shows PartialCollection object. And If I print it as Array(or Arrays.toString(searchResults) it will print me BoxItem.Info object.
I also tried using a different library like GSON, but it was giving me
java. Lang. IllegalArgumentException: class com.box.sdk.BoxUser$Info declares multiple JSON fields named login at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:170)
When I check the BoxSearch code in github I can see they are parsing it via jsonArray but it seems not the case.
Can you suggest me what I might be doing wrong?
My ideal outcome would be something like below (Used developer box Api Try me):
I.e.
{
"total count": 2,
"entries":
"type": "file",
"id": "1234567890",
"etag": "7",
"name": "test.paf",
"shared link": (
"url": https://box.com/s/<random>"
"download_url", "https://box.com/shared/static/<random>"
"vanity _urd": null,
"vanity_ name": null,
"effective access": "collaborators",
"effective _permission": "can preview"
"is _password enabled"; false,
"unshared at"; null,
"download count"; 1,
"preview count": 0,
"access": "collaborators"
"permissions": (
"can preview": true,
"can download": false,
"can edit": false
].
"tags": [
"NoClue"
GET
"type": "file",
"id": "1177053766282",
"etag": "1",
"name"; "Tester.doc"
“shared_link"…
Steps and expectations have been mentioned above
Upvotes: 0
Views: 60
Reputation: 36
Wanted to add this to a comment, but I'm unable to do so. Take a look at this Search Example, and let me know if it helped. If not I'll try to create a sample for you.
I think you may be missing something like this (from the above example):
public static void crawlSearchResultExample(BoxSearchParameters bsp, BoxSearch bs) {
/**
* Example of how to crawl more than 1000+ results in a search query
*/
//Setup Result Partial Object
PartialCollection<BoxItem.Info> searchResults;
//Starting point of the result set
long offset = 0;
//Number of results that would be pulled back
long limit = 1000;
//Storing the full size of the results
long fullSizeOfResult = 0;
while (offset <= fullSizeOfResult) {
searchResults = bs.searchRange(offset, limit, bsp);
fullSizeOfResult = searchResults.fullSize();
print("offset: " + offset + " of fullSizeOfResult: " + fullSizeOfResult);
printSearchResults(searchResults);
offset += limit;
}
}
private static void printSearchResults(PartialCollection<BoxItem.Info> searchResults) {
//Crawl the folder
System.out.println("--==Results fullResultSize: " + searchResults.fullSize() + "==--");
for (BoxItem.Info itemInfo : searchResults) {
System.out.println("File Found: " + itemInfo.getName() + ", Owner: " + itemInfo.getOwnedBy().getID());
}
System.out.println();
}
Upvotes: 0