Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BoxWeblink deserialization #881

Merged
merged 7 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ __New Features and Enhancements:__

- Add file request support ([#869](https://github.com/box/box-java-sdk/pull/869))

__Bug Fixes:__

- Fix `BoxWeblink` deserialization ([#881](https://github.com/box/box-java-sdk/pull/881))

## 2.53.0 [2021-01-08]

__New Features and Enhancements:__
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/box/sdk/BoxWebLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,11 @@ protected void parseJSONMember(JsonObject.Member member) {
try {
if (memberName.equals("url")) {
try {
this.linkURL = new URL(value.asString());
if (value.asString().isEmpty()) {
this.linkURL = null;
} else {
this.linkURL = new URL(value.asString());
}
} catch (MalformedURLException e) {
throw new BoxAPIException("Couldn't parse url for weblink", e);
}
Expand Down
8 changes: 8 additions & 0 deletions src/test/Fixtures/BoxCollection/GetCollectionItems200.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
"etag": "1",
"sha1": "9f425a006e19bb38566af5b2122abd2e0c5dd851",
"name": "Simple Contract Final.pdf"
},
{
"type": "web_link",
"id": "123456",
"sequence_id": "0",
"etag": "0",
"name": "google.com",
"url": ""
}
],
"limit": 100,
Expand Down
8 changes: 7 additions & 1 deletion src/test/java/com/box/sdk/BoxCollectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ public void getCollectionSucceeds() throws IOException {
public void testGetItemsParsesFieldsCorrectly() throws IOException {
String result = "";
final String collectionID = "12345";
final String collectionID2 = "123456";
final String collectionItemsURL = "/collections/12345/items/";
final String collectionName = "Simple Contract Final.pdf";
final String collectionName2 = "google.com";

result = TestConfig.getFixture("BoxCollection/GetCollectionItems200");

Expand All @@ -160,9 +162,13 @@ public void testGetItemsParsesFieldsCorrectly() throws IOException {

BoxCollection collection = new BoxCollection(this.api, collectionID);
Iterator<BoxItem.Info> iterator = collection.getItems().iterator();
BoxItem.Info info = iterator.next();
BoxFile.Info info = (BoxFile.Info) iterator.next();
BoxWebLink.Info info2 = (BoxWebLink.Info) iterator.next();

Assert.assertEquals(collectionID, info.getID());
Assert.assertEquals(collectionName, info.getName());
Assert.assertEquals(collectionID2, info2.getID());
Assert.assertEquals(collectionName2, info2.getName());
Assert.assertEquals(null, info2.getLinkURL());
}
}