Browse Source

Merge pull request #15452 from thingsboard/fix/redis-cache-unknown-properties

Ignore unknown properties when deserializing Redis cache entries
pull/15463/head
Viacheslav Klimov 1 month ago
committed by GitHub
parent
commit
fcdc7b71b7
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 11
      common/cache/src/main/java/org/thingsboard/server/cache/TbJsonRedisSerializer.java

11
common/cache/src/main/java/org/thingsboard/server/cache/TbJsonRedisSerializer.java

@ -18,6 +18,8 @@ package org.thingsboard.server.cache;
import org.springframework.data.redis.serializer.SerializationException;
import org.thingsboard.common.util.JacksonUtil;
import java.io.IOException;
public class TbJsonRedisSerializer<K, V> implements TbRedisSerializer<K, V> {
private final Class<V> clazz;
@ -33,6 +35,13 @@ public class TbJsonRedisSerializer<K, V> implements TbRedisSerializer<K, V> {
@Override
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);
}
}
}

Loading…
Cancel
Save