-
Notifications
You must be signed in to change notification settings - Fork 550
Closed
Labels
bugSomething isn't workingSomething isn't working
Milestone
Description
版本
Springboot: 2.1.3.RELEASE
JAVA: OpenJDK 1.8
fastjson: 2.0.8
问题描述
要存入redis的是一个byte数组
redisTemplate配置有三种情况:
一:使用fastjson1
template.setValueSerializer(new GenericFastJsonRedisSerializer());- 序列化: value会被序列化为16进制的字符串存入redis中;
- 反序列化: 获取时反序列化后直接得到一个byte数组。
二:使用fastjson2 JSON
template.setValueSerializer(new GenericFastJsonRedisSerializer());- 序列化:value会直接作为字符串存入redis中;
- 反序列化:获取时反序列化会得到一个JSONArray,需要做额外的判断的处理....这个怎么配置可以直接得到一个btye数组呢?
三:使用fastjson2 JSONB
template.setValueSerializer(new GenericFastJsonRedisSerializer(true));- 序列化:报错 ArrayIndexOutOfBoundsException
相关日志输出
在JSONWriterJSONB类的public void writeBinary(byte[] bytes)方法中
void ensureCapacity(int minCapacity)
// 这个方法给 this.bytes调整长度,得到的长度比需要序列化的byte数组bytes长了10位,但是在下面的方法中
System.arraycopy(bytes, 0, this.bytes, off, bytes.length);
//off 是11,这样正好把bytes复制到this.bytes时正好少了一位
//导致报错ArrayIndexOutOfBoundsExceptionReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
