Skip to content

fix: route parameterized Collection types to the list reader - #7814

Open
DarrenChangJR wants to merge 1 commit into
alibaba:mainfrom
DarrenChangJR:fix/parameterized-jdk-collections
Open

fix: route parameterized Collection types to the list reader#7814
DarrenChangJR wants to merge 1 commit into
alibaba:mainfrom
DarrenChangJR:fix/parameterized-jdk-collections

Conversation

@DarrenChangJR

Copy link
Copy Markdown

What this PR does and why

Parameterized concrete Collection types not explicitly listed by the base
reader module are currently routed to JavaBean readers unless their raw class is
assignable to ArrayList. They then reject JSON arrays, even though the same
raw classes are correctly treated as collections when passed as Class values.

This change makes the parameterized fallback consistent with the raw-class
path by checking Collection.class.isAssignableFrom(rawClass). The existing
ObjectReaderImplList retains the concrete collection class and generic item
type.

Tests

ParameterizedJdkCollectionTest covers both text JSON and JSONB for:

  • ArrayDeque and PriorityQueue;
  • Vector;
  • LinkedBlockingDeque, LinkedBlockingQueue, and LinkedTransferQueue;
  • PriorityBlockingQueue;
  • CopyOnWriteArraySet.

All values are read as Long, including a value outside the Integer range,
and each result retains its requested concrete class.

Validation performed:

  • focused test: 16 cases, no failures;
  • mvn -pl core validate;
  • clean full core build: 7,990 tests, no failures or errors;
  • external Fastjson 1.2.83 compatibility matrix: eight collection failures
    removed, with unrelated findings unchanged.

Checklist

  • Tests cover text JSON and JSONB.
  • Tests cover list, deque, queue, blocking queue, priority queue, and set
    implementations.
  • The change makes parameterized handling consistent with existing raw
    Collection handling.
  • No public API or documentation change is required.
中文说明

修改内容和原因

当参数化的具体 Collection 类型不在基础 reader 模块的固定列表中时,
当前 fallback 只有在原始类型继承 ArrayList 的情况下才会选择集合 reader。
其他类型会被错误地当作 JavaBean,并在输入 JSON 数组时失败。这与直接传入
同一个原始 Class 时的行为不一致。

本修改将判断改为 Collection.class.isAssignableFrom(rawClass),使参数化
类型和原始类型走相同的集合语义。现有 ObjectReaderImplList 会继续保留
请求的具体集合类型和泛型元素类型。

测试

ParameterizedJdkCollectionTest 对以下类型同时覆盖文本 JSON 和 JSONB:

  • ArrayDequePriorityQueueVector
  • LinkedBlockingDequeLinkedBlockingQueueLinkedTransferQueue
  • PriorityBlockingQueueCopyOnWriteArraySet

所有结果都保留目标具体类型,并把包含超出 Integer 范围的数值读取为
Long。聚焦测试共 16 个用例通过,Maven validate 通过,完整 core
测试共 7,990 个用例通过;外部 1.2.83 兼容矩阵中恰好消除了 8 个相关差异。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant