fastjson版本1.2.51
spring-data-redis版本2.1.0RELEASE
我是这样初始化:
然后注入 存进redis
然后反序列化读取的时候就转换异常了
从redis看存储的json数据好像是没问题的:
网上看到以前的版本别人会手动写一个FastJsonRedisSerializer的serialize和deserialize,但是我看现在已经存在这两个方法了,想着是不是就能直接用了。序列化的差别好像就是 #2060
提到的。在别人的回复 #2083 (comment) 里面提到"FastJsonRedisSerializer反序列化过来对象为JSONObject,建议你自己再转换一次",
但是反序列化的方法不是已经有泛型了?为什么还要再重复的转换一次呢?官方都没有好的解决方案吗?
我的配置跟这个一样,不过我是用的是:GenericFastJsonRedisSerializer,配置使用的是默认的配置。我的序列化很好,但是反序列化的时候出现异常:
org.springframework.data.redis.serializer.SerializationException: Could not deserialize: not close json text, token : error; nested exception is com.alibaba.fastjson.JSONException: not close json text, token : error
at com.alibaba.fastjson.support.spring.GenericFastJsonRedisSerializer.deserialize(GenericFastJsonRedisSerializer.java:37)
at org.springframework.data.redis.core.AbstractOperations.deserializeValue(AbstractOperations.java:335)
at org.springframework.data.redis.core.AbstractOperations$ValueDeserializingRedisCallback.doInRedis(AbstractOperations.java:61)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:228)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:188)
at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:96)
at org.springframework.data.redis.core.DefaultValueOperations.get(DefaultValueOperations.java:53)
at com.xxxxxxx.xxxxxxxxx.service.service.impl.CacheServiceImpl.get(CacheServiceImpl.java:92)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:205)
at com.sun.proxy.$Proxy90.get(Unknown Source)
at com.xxxxxxxx.xxxxxxx.service.service.impl.WeiXinAuthFactory.accessToken(WeiXinAuthFactory.java:41)
at com.xxxxxxxx.xxxxxxxxx.reactor.listener.TemplateMsgListener.onApplicationEvent(TemplateMsgListener.java:39)
at com.xxxxxxx.xxxxxxxxxx.reactor.listener.TemplateMsgListener.onApplicationEvent(TemplateMsgListener.java:20)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:158)
at org.springframework.context.event.SimpleApplicationEventMulticaster.lambda$multicastEvent$0(SimpleApplicationEventMulticaster.java:136)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: com.alibaba.fastjson.JSONException: not close json text, token : error
at com.alibaba.fastjson.parser.DefaultJSONParser.close(DefaultJSONParser.java:1527)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:400)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:359)
at com.alibaba.fastjson.support.spring.GenericFastJsonRedisSerializer.deserialize(GenericFastJsonRedisSerializer.java:35)
... 23 common frames omitted
而且这个Value序列化的时候,就是使用的GenericFastJsonRedisSerializer,但是它自己反序列话的时候,确不行了。有一点是,我序列化的内容里面可能会有下划线,真糟心