本文整理汇总了Java中org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer类的典型用法代码示例。如果您正苦于以下问题:Java Jackson2JsonRedisSerializer类的具体用法?Java Jackson2JsonRedisSerializer怎么用?Java Jackson2JsonRedisSerializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Jackson2JsonRedisSerializer类属于org.springframework.data.redis.serializer包,在下文中一共展示了Jackson2JsonRedisSerializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: redisTemplate
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; //导入依赖的package包/类
@Bean(name="redisTemplate")
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
RedisTemplate<String, String> template = new RedisTemplate<>();
RedisSerializer<String> redisSerializer = new StringRedisSerializer();
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
template.setConnectionFactory(factory);
//key序列化方式
template.setKeySerializer(redisSerializer);
//value序列化
template.setValueSerializer(jackson2JsonRedisSerializer);
//value hashmap序列化
template.setHashValueSerializer(jackson2JsonRedisSerializer);
return template;
}
示例2: redisTemplate
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; //导入依赖的package包/类
/**
* RedisTemplate配置
* @param factory
* @return
*/
@Bean
@SuppressWarnings({"rawtypes", "unchecked"})
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
StringRedisTemplate template = new StringRedisTemplate(factory);
//定义value的序列化方式
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
template.setValueSerializer(jackson2JsonRedisSerializer);
template.setHashValueSerializer(jackson2JsonRedisSerializer);
template.afterPropertiesSet();
return template;
}
示例3: redisTemplate
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; //导入依赖的package包/类
@Bean("redisTemplate") //新家的这个注解 10-26 12:06
@SuppressWarnings({ "rawtypes", "unchecked" })
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory redisFactory){
StringRedisTemplate template = new StringRedisTemplate(redisFactory);
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new
Jackson2JsonRedisSerializer(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
template.setValueSerializer(jackson2JsonRedisSerializer);
template.afterPropertiesSet();
return template;
}
示例4: redisTemplate
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; //导入依赖的package包/类
@Bean
public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<Object, Object> template = new RedisTemplate<>();
template.setConnectionFactory(connectionFactory);
//使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值
Jackson2JsonRedisSerializer serializer = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper mapper = new ObjectMapper();
mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
serializer.setObjectMapper(mapper);
template.setValueSerializer(serializer);
//使用StringRedisSerializer来序列化和反序列化redis的key值
template.setKeySerializer(new StringRedisSerializer());
template.afterPropertiesSet();
return template;
}
示例5: redisCacheRedisTemplate
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; //导入依赖的package包/类
@Bean
public RedisTemplate<Object, Object> redisCacheRedisTemplate() {
RedisTemplate<Object, Object> template = new RedisTemplate<>();
template.setConnectionFactory(connectionFactory);
Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
template.setKeySerializer(jackson2JsonRedisSerializer);
template.setValueSerializer(jackson2JsonRedisSerializer);
return template;
}
示例6: redisTemplate
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; //导入依赖的package包/类
@Bean
public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory factory) throws UnknownHostException {
RedisTemplate<Object, Object> template = new RedisTemplate<>();
template.setConnectionFactory(factory);
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper mapper = new ObjectMapper();
mapper.findAndRegisterModules();
mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(mapper);
template.setValueSerializer(jackson2JsonRedisSerializer);
template.setKeySerializer(new StringRedisSerializer());
template.afterPropertiesSet();
return template;
}
示例7: redisTemplate
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; //导入依赖的package包/类
@Bean
public RedisOperations<String, Request> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<String, Request> template = new RedisTemplate<String, Request>();
template.setConnectionFactory(redisConnectionFactory);
RedisSerializer<String> keySerializer = new StringRedisSerializer();
Jackson2JsonRedisSerializer<Request> requestSerializer = new Jackson2JsonRedisSerializer<Request>(Request.class);
template.setKeySerializer(keySerializer);
template.setValueSerializer(requestSerializer);
template.setHashKeySerializer(keySerializer);
template.setHashValueSerializer(requestSerializer);
return template;
}
示例8: redisTemplate
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; //导入依赖的package包/类
@Bean
public RedisTemplate<String, Album> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<String, Album> template = new RedisTemplate<>();
template.setConnectionFactory(redisConnectionFactory);
RedisSerializer<String> stringSerializer = new StringRedisSerializer();
RedisSerializer<Album> albumSerializer = new Jackson2JsonRedisSerializer<>(Album.class);
template.setKeySerializer(stringSerializer);
template.setValueSerializer(albumSerializer);
template.setHashKeySerializer(stringSerializer);
template.setHashValueSerializer(albumSerializer);
return template;
}
示例9: redisTemplate
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; //导入依赖的package包/类
@SuppressWarnings({"unchecked","rawtypes"})
@Bean
public RedisTemplate<String, String> redisTemplate(
RedisConnectionFactory factory) {
StringRedisTemplate template = new StringRedisTemplate(factory);
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
template.setValueSerializer(jackson2JsonRedisSerializer);
template.afterPropertiesSet();
return template;
}
示例10: reactiveJsonPostRedisTemplate
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; //导入依赖的package包/类
@Bean
public ReactiveRedisTemplate<String, Post> reactiveJsonPostRedisTemplate(
ReactiveRedisConnectionFactory connectionFactory) {
RedisSerializationContext<String, Post> serializationContext = RedisSerializationContext
.<String, Post>newSerializationContext(new StringRedisSerializer())
.hashKey(new StringRedisSerializer())
.hashValue(new Jackson2JsonRedisSerializer<>(Post.class))
.build();
return new ReactiveRedisTemplate<>(connectionFactory, serializationContext);
}
示例11: redisTemplate
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; //导入依赖的package包/类
@Bean
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
StringRedisTemplate template = new StringRedisTemplate(factory);
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
template.setValueSerializer(jackson2JsonRedisSerializer);
template.afterPropertiesSet();
return template;
}
示例12: jsonRedisTemplate
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; //导入依赖的package包/类
private RedisTemplate jsonRedisTemplate(JedisConnectionFactory jedisConnectionFactory, Class<?> clazz) {
RedisTemplate template = new RedisTemplate();
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new Jackson2JsonRedisSerializer(clazz));
template.setHashKeySerializer(new StringRedisSerializer());
template.setHashValueSerializer(new Jackson2JsonRedisSerializer(clazz));
template.setConnectionFactory(jedisConnectionFactory);
return template;
}
示例13: jsonRedisSerializer
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; //导入依赖的package包/类
private Jackson2JsonRedisSerializer jsonRedisSerializer(JavaType javaType)
{
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(javaType);
ObjectMapper mapper = new ObjectMapper();
mapper.enableDefaultTyping();
mapper.enableDefaultTyping(DefaultTyping.NON_FINAL, As.PROPERTY);
mapper.findAndRegisterModules();
mapper.registerModule(new Jackson2HalModule());
mapper.setHandlerInstantiator(new Jackson2HalModule.HalHandlerInstantiator(new DefaultRelProvider(), null, null));
jackson2JsonRedisSerializer.setObjectMapper(mapper);
return jackson2JsonRedisSerializer;
}
示例14: redisTemplate
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; //导入依赖的package包/类
@Bean
@SuppressWarnings({ "rawtypes", "unchecked" })
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
StringRedisTemplate template = new StringRedisTemplate(factory);
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
template.setValueSerializer(jackson2JsonRedisSerializer);
template.afterPropertiesSet();
return template;
}
示例15: template
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; //导入依赖的package包/类
@Bean
public HwRedisTemplate template(HwRedisConnectionFactory factory) {
// 序列化
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);
// 实例化template
HwRedisTemplate hwRedisTemplate = new HwRedisTemplate();
hwRedisTemplate.setConnectionFactory(factory);
hwRedisTemplate.setValueSerializer(jackson2JsonRedisSerializer);
return hwRedisTemplate;
}