package org.onetwo.boot.module.redis;

import org.onetwo.common.jackson.JsonMapper;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;

import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectMapper.DefaultTyping;

/**
 * @author wayshall
 * <br/>
 */
public class JsonRedisTemplate extends RedisTemplate<String, Object>{

	public JsonRedisTemplate(RedisConnectionFactory connectionFactory) {
		this();
		setConnectionFactory(connectionFactory);
		afterPropertiesSet();
	}

	public JsonRedisTemplate() {
		JsonMapper jsonMapper = JsonMapper.ignoreNull();
		ObjectMapper mapper = jsonMapper.getObjectMapper();
		mapper.enableDefaultTyping(DefaultTyping.NON_FINAL, As.PROPERTY);
		
//		RedisSerializer<String> keySerializer = new StringRedisSerializer();
		RedisSerializer<Object> keySerializer = new GenericJackson2JsonRedisSerializer(mapper);
		RedisSerializer<Object> valueSerializer = new GenericJackson2JsonRedisSerializer(mapper);
		setKeySerializer(keySerializer);
		setValueSerializer(valueSerializer);
		setHashKeySerializer(keySerializer);
		setHashValueSerializer(valueSerializer);
	}
	
}

@@ -930,16 +930,18 @@
 pper();%0A
+//
 %09%09mapper
@@ -999,16 +999,150 @@
 OPERTY);
+//%E7%94%A8%E8%BF%99%E4%B8%AA%E9%85%8D%E7%BD%AE%EF%BC%8C%E5%A6%82%E6%9E%9C%E5%86%99%E5%85%A5%E7%9A%84%E5%AF%B9%E8%B1%A1%E6%98%AFlist%EF%BC%8C%E5%B9%B6%E4%B8%94%E5%85%83%E7%B4%A0%E6%98%AF%E5%A4%8D%E5%90%88%E5%AF%B9%E8%B1%A1%E6%97%B6%EF%BC%8C%E4%BC%9A%E6%8A%9B%E9%94%99%EF%BC%9ACurrent context not Object but Array%0A%09%09mapper.enableDefaultTyping(DefaultTyping.JAVA_LANG_OBJECT);
 %0A%09%09%0A//%09%09

fix redis json template