|
|
@ -18,6 +18,8 @@ package org.thingsboard.server.cache; |
|
|
import org.springframework.data.redis.serializer.SerializationException; |
|
|
import org.springframework.data.redis.serializer.SerializationException; |
|
|
import org.thingsboard.common.util.JacksonUtil; |
|
|
import org.thingsboard.common.util.JacksonUtil; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
|
public class TbJsonRedisSerializer<K, V> implements TbRedisSerializer<K, V> { |
|
|
public class TbJsonRedisSerializer<K, V> implements TbRedisSerializer<K, V> { |
|
|
|
|
|
|
|
|
private final Class<V> clazz; |
|
|
private final Class<V> clazz; |
|
|
@ -33,6 +35,13 @@ public class TbJsonRedisSerializer<K, V> implements TbRedisSerializer<K, V> { |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public V deserialize(K key, byte[] bytes) throws SerializationException { |
|
|
public V deserialize(K key, byte[] bytes) throws SerializationException { |
|
|
return JacksonUtil.fromBytes(bytes, clazz); |
|
|
if (bytes == null) { |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
try { |
|
|
|
|
|
return JacksonUtil.IGNORE_UNKNOWN_PROPERTIES_JSON_MAPPER.readValue(bytes, clazz); |
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
throw new SerializationException("Failed to deserialize cached value", e); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|