[BUG]在版本2.0.50中,Object[]数组对象序列化后存入redis缓存,不能取出
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 613
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 6
Description
### 问题描述
*我们配置了redis的hash存储的GenericFastJsonRedisSerializer序列化,我们在存入缓存的时候可以通过这个序列化存入,但是取出来的时候只能拿到一个@value*
### 环境信息
*本地调试*
- OS信息: windows11 cpu=4 men=16GB
- JDK信息:1.8
- 版本信息:Fastjson2 2.0.50
### 重现步骤
*存入的内容格式,如下:*
```json
{
"@type": "[com.xxx.ProtocolParamEntity",
"@value": [
{
"id": "1",
"bit": "0"
},
{
"id": "2",
"bit": "1"
},
null,
null
]
}
```
*数据存入到redis之后,通过hash取出来,到obj对象,但是这个对象的值是@value,根本无法转换成ProtocolParamEntity[]*
```java
private ProtocolParamEntity[] getHash(String protocolId, String address) {
String hash = PhnixConstants.CACHE_PROTOCAL_PARAM_PREFIX + protocolId;
Object obj = redisDataBase.db0().getOpsForHashValue(hash, address);
if (null == obj) {
return new ProtocolParamEntity[0];
}
return (ProtocolParamEntity[])obj;
}
```
### 期待的正确结果
**能够正常取出
### 相关日志输出
*请复制并粘贴任何相关的日志输出。*
#### 附加信息
1、我们引入的是兼容fastjson1的依赖:[Fastjson1 Compatible](https://mvnrepository.com/artifact/com.alibaba/fastjson) » [2.0.50](https://mvnrepository.com/artifact/com.alibaba/fastjson/2.0.50)
2、redis客户端配置代码
```
RedisTemplate template = new RedisTemplate<>();
template.setConnectionFactory(lettuceConnectionFactory);
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new GenericFastJsonRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());
template.setHashValueSerializer(new GenericFastJsonRedisSerializer());
return template;
```
我存入的时候正常,redis的格式是:
```
{
"@type": "[com.xxx.ProtocolParamEntity",
"@value": [
{
"id": "1",
"bit": "0"
},
{
"id": "2",
"bit": "1"
},
null,
null
]
}
```
取出来不正常,也不报错,就是只取出了个@value
用的是这个序列化实现:com.alibaba.fastjson.support.spring.GenericFastJsonRedisSerializer
Contributor guide
Research direction
Start by reproducing the issue with GenericFastJsonRedisSerializer through the configured RedisTemplate hash value serializer, using a ProtocolParamEntity[] containing null elements. Compare the stored JSON with the object returned by getOpsForHashValue. Done means the retrieved value can be cast to ProtocolParamEntity[] with its elements and nulls preserved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, redis
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100