当前位置: 首页>>代码示例>>Java>>正文


Java Jackson2JsonRedisSerializer类代码示例

本文整理汇总了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;
}
 
开发者ID:cwenao,项目名称:springboot_cwenao,代码行数:25,代码来源:RedisConfig.java

示例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;
}
 
开发者ID:SnailFastGo,项目名称:springboot_op,代码行数:22,代码来源:RedisConfiguration.java

示例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;
}
 
开发者ID:duanyaxin,项目名称:springboot-smart,代码行数:17,代码来源:RedisConfiguration.java

示例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;
}
 
开发者ID:fanqinghui,项目名称:action,代码行数:20,代码来源:RedisUtil.java

示例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;
}
 
开发者ID:lodsve,项目名称:lodsve-framework,代码行数:17,代码来源:RedisCacheConfiguration.java

示例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;
}
 
开发者ID:nonocast,项目名称:todolist,代码行数:20,代码来源:CacheConfig.java

示例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;
}
 
开发者ID:trustedanalytics,项目名称:data-acquisition,代码行数:17,代码来源:CloudStoreConfig.java

示例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;
}
 
开发者ID:scottfrederick,项目名称:spring-music,代码行数:17,代码来源:RedisConfig.java

示例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;  
   }
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:15,代码来源:RedisConfig.java

示例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);
}
 
开发者ID:hantsy,项目名称:spring-reactive-sample,代码行数:14,代码来源:DemoApplication.java

示例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;
}
 
开发者ID:ChinaLHR,项目名称:JavaQuarkBBS,代码行数:13,代码来源:RedisConfig.java

示例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;
}
 
开发者ID:veritasware,项目名称:neto,代码行数:10,代码来源:AppConfig.java

示例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;
}
 
开发者ID:Azure,项目名称:CityPower-Build-Sample,代码行数:14,代码来源:CacheConfig.java

示例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;
}
 
开发者ID:lemon-china,项目名称:lemon-dubbo-message,代码行数:14,代码来源:RedisConfiguration.java

示例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;
}
 
开发者ID:Fourwenwen,项目名称:consistent-hashing-redis,代码行数:15,代码来源:CacheConfig.java


注:本文中的org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。