Redistemplate default serialization mode is Jdkserializeable, stringredistemplate default serialization is Stringredisserializer
You can change the serialization of redistemplate by manually configuring it
Package Com.wenbronk.data.redis;
Import Com.fasterxml.jackson.annotation.JsonAutoDetect;
Import Com.fasterxml.jackson.annotation.PropertyAccessor;
Import Com.fasterxml.jackson.databind.ObjectMapper;
Import org.springframework.boot.SpringApplication;
Import org.springframework.boot.autoconfigure.SpringBootApplication;
Import Org.springframework.context.annotation.Bean;
Import Org.springframework.data.redis.connection.RedisConnectionFactory;
Import Org.springframework.data.redis.core.RedisTemplate;
Import Org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
Import Org.springframework.data.redis.serializer.StringRedisSerializer;
/** * Redis Startup class * Created by Wenbronk on 2017/6/12. */@SpringBootApplication public class Redisapplication {public static void main (string[] args) {springappli
Cation.run (Redisapplication.class, args); }/** * Redistemplate serialization using jdkserializeable, storing binary bytecode, so custom serialization class * @param redisconnectionfactory * @r ETurn */@Bean public redistemplate<object, object> redistemplate (redisconnectionfactory redisconnection
Factory) {redistemplate<object, object> redistemplate = new redistemplate<> ();
Redistemplate.setconnectionfactory (redisconnectionfactory); Replace the default serialization Jackson2jsonredisserializer Jackson2jsonredisserializer = new Jackson2Json using Jackson2jsonredisserialize
Redisserializer (Object.class);
Objectmapper objectmapper = new Objectmapper ();
Objectmapper.setvisibility (Propertyaccessor.all, JsonAutoDetect.Visibility.ANY);
Objectmapper.enabledefaulttyping (ObjectMapper.DefaultTyping.NON_FINAL);
Jackson2jsonredisserializer.setobjectmapper (Objectmapper);
Sets the serialization rule for value and the serialization rule for key Redistemplate.setvalueserializer (Jackson2jsonredisserializer);
Redistemplate.setkeyserializer (New Stringredisserializer ());
Redistemplate.afterpropertiesset ();
return redistemplate; }
}