fastjson2
fastjson2 copied to clipboard
SimpleGrantedAuthority 反序列化报错[BUG]
问题描述
简要描述您碰到的问题。
登陆授权信息反序列化拿不到属性。1.2.83 正常。
环境信息
请填写以下信息:
- OS信息: mac
- JDK信息: [e.g.:Openjdk 1.8.0_312]
- 版本信息:[e.g.:Fastjson2 2.0.42]
重现步骤
如何操作可以重现该问题:
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.
2.0.42没有复现
2.0.42没有复现
![]()
具体的原因我也不清楚,因为我已经发布到正式环境,使用缓存出现这个错误才发现的。然后经过本地测试也确实是复现了这个错误。目前依然如此,包括使用最新的,2.0.43
我都已经忘记这个问题了。结果今天更新了2.0.51 突然发现修复了,导致我自定义实现的兼容类又不能解析了, 哎~又得重新删掉自定义实现类,删掉缓存~ 本以为这样就好了,痛苦的是,结果发现fastjson2.useJacksonAnnotation=false 这个配置不生效了~ (手动痛苦🎭)