Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

ListRecord.Field array-shaped `message` still fails in the production GsonFactory (follow-up to #1587)

未关闭 适合新手
#1,653 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
74/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
java
领域
api

调研方向

从 GsonFactory.registerTypeAdapters 和 GsonListViewGroupingFactory 开始;issue 提议将 GsonListRecordFieldFactory 移到 slack-api-model/src/main/java/com/slack/api/util/json/,并在生产工厂中注册它。查看现有的测试适配器和 ListRecordFieldTest,了解对单个对象和数组的预期处理方式。生产环境中的 GsonFactory 能成功解析这两种形式后,工作即告完成。

由索引模型根据 Issue 内容生成。

描述

Issue summary

When the Slack API returns a conversations.replies (or conversations.history) response that contains a Slack Lists item attachment, the SDK throws JsonSyntaxException whenever any ListRecord.Field.message value is a JSON array instead of a single object. The whole API call fails, and no Message data is returned.

This is the bug from #1587. #1590 (released in v1.49.0) closed #1587, but the bug is still in the production code path in v1.52.0.

Affected versions

  • v1.46.0 through v1.48.1 (verified in #1587; also seen in production on v1.48.1)
  • v1.49.0 through v1.52.0: the production GsonFactory has no adapter for ListRecord.Field. @maoppay saw the failure on v1.50.0 (comment in #1587), and the live probe in #1644 shows it too.

Why #1590 was not sufficient

#1590 changed two things:

  1. ListRecord.Field (slack-api-model/src/main). It added private transient List<Message> messages and getMessages() / setMessages(). The field message is still a single Message. Gson skips transient fields and sets fields by reflection, not through setters. So without an adapter, Gson still maps the JSON key message to the Message field, and an array still fails.
  2. GsonListRecordFieldFactory, the adapter that converts the array. #1590 put it in slack-api-model/src/test/java/test_locally/util/list/ and registered it only in the test GsonFactory (slack-api-model/src/test/java/test_locally/unit/GsonFactory.java).

ListRecordFieldTest parses with that test GsonFactory, so it passes. Real API calls parse with com.slack.api.util.json.GsonFactory in slack-api-client (MethodsClientImpl calls GsonFactory.createSnakeCase(config)), and that class does not register the adapter. Also, the json-logs/samples/api samples still have message as a single object, so the MockSlackApi tests (for example ConversationsTest) never see the array shape.

Minimal reproduction

import com.google.gson.Gson;
import com.slack.api.methods.response.conversations.ConversationsRepliesResponse;
import com.slack.api.util.json.GsonFactory;

public class Repro {
    public static void main(String[] args) {
        // Mirrors the shape Slack returns when a Lists item's `message` field
        // has multiple values (array form).
        String payload =
            "{\"ok\":true,\"messages\":[{\"type\":\"message\",\"user\":\"U1\",\"ts\":\"1.0\","
            + "\"text\":\"hi\",\"attachments\":[{\"list_record\":{\"record\":{\"fields\":["
            + "{\"key\":\"name\",\"message\":{\"text\":\"ok\"}},"
            + "{\"key\":\"details\",\"message\":[{\"text\":\"a\"},{\"text\":\"b\"}]}"
            + "]}}}]}]}";

        Gson sdkGson = GsonFactory.createSnakeCase();
        // Still throws JsonSyntaxException on v1.52.0 at
        // $.messages[0].attachments[0].list_record.record.fields[1].message
        ConversationsRepliesResponse parsed =
            sdkGson.fromJson(payload, ConversationsRepliesResponse.class);
    }
}

Expected behavior

The SDK accepts both single-object and array shapes for ListRecord.Field.message in real API responses, as getMessages() from #1590 intends.

Proposed fix

#1654 moves GsonListRecordFieldFactory to slack-api-model/src/main/java/com/slack/api/util/json/ (next to GsonListViewGroupingFactory) and registers it in GsonFactory.registerTypeAdapters.

主要语言
Java
星标
602
派生
235
平均合并
2 天 13 小时
30 天内合并 PR
8

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

slackapi/java-slack-sdk 的其他 Issue

查看 slackapi/java-slack-sdk 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。