zoukankan      html  css  js  c++  java
  • Could not read JSON: Unexpected character ('¬' (code 172)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')

    今天spring boot2.3.0整合redis进行JSON的缓存,报了这么一个错:

    org.springframework.data.redis.serializer.SerializationException: Could not read JSON: Unexpected character ('¬' (code 172)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')org.springframework.data.redis.serializer.SerializationException: Could not read JSON: Unexpected character ('¬' (code 172)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')

    解决:之前的序列化方式不是JSON的,但是已经缓存到Redis中没有删除,所以……

    过程:

    嗯……搞不懂,说我序列化失败,早来找去都不知道错哪了,鉴于RedisCacheManager是复制过来的,就去看了看源代码,也没觉得这个代码写错了。

    然后搞来搞去,浪费了2个半小时,后来没办法,我又重新开始,回到上一步的直接用原本的序列化方法,不用json序列化,然后又给我报了个错:序列化的UID不匹配,嗯……刚前不久改了下UID,他这个报错我再是明白了,redis之前的缓存没有删除

    回到Redis删除键,再来一次,成功。

    附上代码:

    @Configuration
    public class MyRedisConfig {
    
    
        @Bean
        public RedisCacheManager redisCacheManager (RedisConnectionFactory redisConnectionFactory){
    //初始化一个redisCacheWriter
            RedisCacheWriter redisCacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory);
    //初始化序列化方式为json
            RedisSerializer redisSerializer = new GenericJackson2JsonRedisSerializer();
            RedisSerializationContext.SerializationPair pair = RedisSerializationContext.SerializationPair.fromSerializer(redisSerializer);
            RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig().serializeValuesWith(pair);
    
            return new RedisCacheManager(redisCacheWriter,redisCacheConfiguration);
        }
    }
  • 相关阅读:
    React 官网列子学习
    阿里云图片裁剪
    Android list加载图片工具类
    Java 反射
    Android 调节图片工具类
    Android 设置资源字体,屏幕截图
    android 跨进程通讯 AIDL
    android sdk api结构解析
    android学习之activity
    驱动进阶1
  • 原文地址:https://www.cnblogs.com/woyujiezhen/p/12958133.html
Copyright © 2011-2022 走看看