Spring-data-redis @Cacheable java.lang.ClassCastException: java.util.HashMap cannot be cast to java.lang.String

久未见 提交于 2019-12-04 10:25:00
Gipple Lake

when storing hash object,redis will work with Jackson2JsonRedisSerializer which can be used to bind to typed beans, or untyped instances.

redisTemplate.setHashValueSerializer(new Jackson2JsonRedisSerializer<>(Object.class));
yanfeng wang

You need to set setObjectMapper

Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new 
Jackson2JsonRedisSerializer<Object>(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!