Skip to content

Commit 5901635

Browse files
committed
Handle more properties
1 parent c79b3ea commit 5901635

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

slack-api-model/src/main/java/com/slack/api/util/json/GsonFileFactory.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,19 @@ public File deserialize(JsonElement json, Type typeOfT, JsonDeserializationConte
2727
throws JsonParseException {
2828
final JsonObject jsonObject = json.getAsJsonObject();
2929
// Remove unusual data structure form Slack API server
30+
// As the starting point in Jan 2025, we just ignore these non-array properties,
31+
// but we may want to assign to a different field if it's necessary for some use cases
3032
// See https://github.com/slackapi/java-slack-sdk/issues/1426 for more details
33+
if (jsonObject.has("favorites") && !jsonObject.get("favorites").isJsonArray()) {
34+
jsonObject.remove("favorites");
35+
}
36+
if (jsonObject.has("channels") && !jsonObject.get("channels").isJsonArray()) {
37+
jsonObject.remove("channels");
38+
}
39+
if (jsonObject.has("ims") && !jsonObject.get("ims").isJsonArray()) {
40+
jsonObject.remove("ims");
41+
}
3142
if (jsonObject.has("groups") && !jsonObject.get("groups").isJsonArray()) {
32-
// As the starting point in Jan 2025, we just ignore this property,
33-
// but we may want to assign to a different field if it's necessary for some use cases
3443
jsonObject.remove("groups");
3544
}
3645
if (jsonObject.has("shares")) {

slack-api-model/src/test/java/test_locally/api/model/FileTest.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class FileTest {
4040
" \"lines\": 5,\n" +
4141
" \"lines_more\": 0,\n" +
4242
" \"preview_is_truncated\": false,\n" +
43-
" \"favorites\": [],\n" +
43+
" \"favorites\": {},\n" + // unusual data structure here
4444
" \"is_starred\": false,\n" +
4545
" \"shares\": {\n" +
4646
" \"public\": {\n" +
@@ -70,12 +70,9 @@ public class FileTest {
7070
" ]\n" +
7171
" }\n" +
7272
" },\n" +
73-
" \"channels\": [\n" +
74-
" \"C03E94MKU\",\n" +
75-
" \"C03E94MKS\"\n" +
76-
" ],\n" +
73+
" \"channels\": {},\n" + // unusual data structure here
7774
" \"groups\": {},\n" + // unusual data structure here
78-
" \"ims\": [],\n" +
75+
" \"ims\": {},\n" + // unusual data structure here
7976
" \"has_more_shares\": false,\n" +
8077
" \"has_rich_preview\": false,\n" +
8178
" \"file_access\": \"visible\",\n" +
@@ -85,7 +82,7 @@ public class FileTest {
8582
@Test
8683
public void issue1426_parse() {
8784
// com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 65 column 14 path $.groups
88-
File message = GsonFactory.createSnakeCase().fromJson(ISSUE_1426_JSON, File.class);
89-
assertThat(message.getShares(), is(notNullValue()));
85+
File file = GsonFactory.createSnakeCase().fromJson(ISSUE_1426_JSON, File.class);
86+
assertThat(file.getShares(), is(notNullValue()));
9087
}
9188
}

0 commit comments

Comments
 (0)