[BUG]反序列化出现input not end
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 613
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 6
Description
### 问题描述
反序列化时出现input not end,在本机上反序列化正常,上生产就报错
### 环境信息
*请填写以下信息:*
- OS信息: alpine
- JDK信息: jdk21
- 版本信息:2.0.52
### 重现步骤
使用spring缓存,fastjson2序列化器。
`public class FastJsonRedisSerializer implements RedisSerializer {
private final Class clazz;
public FastJsonRedisSerializer(Class clazz) {
super();
this.clazz = clazz;
}
@Override
public byte[] serialize(T t) throws SerializationException {
if (t == null) {
return new byte[0];
}
return JSON.toJSONBytes(t, JSONWriter.Feature.WriteClassName);
}
@Override
public T deserialize(byte[] bytes) throws SerializationException {
if (bytes == null || bytes.length <= 0) {
return null;
}
return JSON.parseObject(bytes, new TypeReference(){}.getType(), JSONReader.Feature.SupportAutoType);
}
}
@Bean
public CacheManager cacheManager(RedisConnectionFactory connectionFactory) {
//缓存配置
Map redisCacheConfigurationMap = new HashMap<>();
Arrays.stream(RedisKeyEnum.values()).forEach(redisKeyEnum ->
redisCacheConfigurationMap.put(redisKeyEnum.getName(), RedisCacheConfiguration.defaultCacheConfig()
.entryTtl(Duration.ofSeconds(redisKeyEnum.getTimeout()))
.computePrefixWith(getKeyPrefix())
.disableCachingNullValues()
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()))
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(fastJsonRedisSerializer()))
));
//初始化一个RedisCacheWriter
RedisCacheWriter redisCacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory);
RedisCacheConfiguration defaultCacheConfig = RedisCacheConfiguration.defaultCacheConfig();
//设置默认过期时间是30秒
defaultCacheConfig.entryTtl(Duration.ofSeconds(3000));
defaultCacheConfig.computePrefixWith(getKeyPrefix());
//初始化RedisCacheManager
return new RedisCacheManager(redisCacheWriter, defaultCacheConfig, redisCacheConfigurationMap);
}`
### 相关日志输出
com.alibaba.fastjson2.JSONException: offset 74, character :, line 1, column 74, fastjson-version 2.0.52 [{"@type":"cn.zymaster.service.core.api.dto.resp.ImgRespDTO","businessId":7L,"businessType":"ADVERTISING_POSITION","businessTypeDesc":"广告运营位","createTime":"2022-09-28 16:20:59","customLink":0,"dataStatus":1,"id":9010486L,"imgFullPath":"/ALL/advertising/8125420220928.png","updateTime":"2022-09-28 16:20:59"}]
at com.alibaba.fastjson2.JSONReader.readArray(JSONReader.java:2600)
at com.alibaba.fastjson2.reader.ObjectReaderImplObject.readObject(ObjectReaderImplObject.java:279)
at com.alibaba.fastjson2.JSON.parseObject(JSON.java:1686)
at cn.zymaster.service.lib.redis.serializer.FastJsonRedisSerializer.deserialize(FastJsonRedisSerializer.java:38)
at org.springframework.data.redis.serializer.DefaultRedisElementReader.read(DefaultRedisElementReader.java:46)
at org.springframework.data.redis.serializer.RedisSerializationContext$SerializationPair.read(RedisSerializationContext.java:277)
at org.springframework.data.redis.cache.RedisCache.deserializeCacheValue(RedisCache.java:390)
at org.springframework.data.redis.cache.RedisCache.lookup(RedisCache.java:209)
at org.springframework.cache.support.AbstractValueAdaptingCache.get(AbstractValueAdaptingCache.java:58)
at org.springframework.cache.interceptor.AbstractCacheInvoker.doGet(AbstractCacheInvoker.java:73)
at org.springframework.cache.interceptor.CacheAspectSupport.findInCaches(CacheAspectSupport.java:518)
at org.springframework.cache.interceptor.CacheAspectSupport.findCachedValue(CacheAspectSupport.java:481)
at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:431)
at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:395)
at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:74)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:18
Contributor guide
Research direction
Start with the supplied FastJsonRedisSerializer.java:38 and the JSON.parseObject path, then inspect the JSONReader.readArray stack location. Reproduce the Spring cache deserialization using fastjson2 2.0.52 on Alpine with JDK 21 and the logged payload; done means the environment-specific failure is explained and covered by a focused regression test or a clearly identified parser issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, redis, spring
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100