alibaba / alibaba/fastjson2

SimpleGrantedAuthority 反序列化报错[BUG]

Open
#2,090 4 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
4.4k
Forks
613
Avg merge
1d 22h
Merged PRs (30d)
6

Description

### 问题描述
*简要描述您碰到的问题。*

登陆授权信息反序列化拿不到属性。1.2.83 正常。

### 环境信息
*请填写以下信息:*

- OS信息: mac
- JDK信息: [e.g.:Openjdk 1.8.0_312]
- 版本信息:[e.g.:Fastjson2 2.0.42]

### 重现步骤
*如何操作可以重现该问题:*

```java
static final Filter autoTypeFilter = JSONReader.autoTypeFilter(
// 按需加上需要支持自动类型的类名前缀,范围越小越安全
"org.springframework.security.core.authority.SimpleGrantedAuthority"
);

public static void main(String[] args) {
System.out.println(JSON.parseObject("\n" +
" {\"@type\": \"org.springframework.security.core.authority.SimpleGrantedAuthority\",\n" +
" \"authority\": \"dept:add\"\n" +
" }", SimpleGrantedAuthority.class, autoTypeFilter));
}
```

### 期待的正确结果
*对您期望发生的结果进行清晰简洁的描述。*

正确结果打印出:dept:add

### 相关日志输出
*请复制并粘贴任何相关的日志输出。*

Exception in thread "main" java.lang.IllegalArgumentException: A granted authority textual representation is required
at org.springframework.util.Assert.hasText(Assert.java:289)
at org.springframework.security.core.authority.SimpleGrantedAuthority.(SimpleGrantedAuthority.java:39)
at com.alibaba.fastjson2.reader.ConstructorFunction.apply(ConstructorFunction.java:148)
at com.alibaba.fastjson2.reader.ConstructorFunction.apply(ConstructorFunction.java:15)
at com.alibaba.fastjson2.reader.ObjectReaderNoneDefaultConstructor.readObject(ObjectReaderNoneDefaultConstructor.java:327)
at com.alibaba.fastjson2.JSON.parseObject(JSON.java:768)

Contributor guide

Open the contributing guide

Research direction

Run the provided JSON.parseObject example with SimpleGrantedAuthority and inspect the stack-trace path through ConstructorFunction and ObjectReaderNoneDefaultConstructor. Compare the current behavior with fastjson2 1.2.83; done means the authority field deserializes to the expected “dept:add” value without the IllegalArgumentException.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.