diff --git a/java/src/main/java/com/genexus/cache/redis/RedisClient.java b/java/src/main/java/com/genexus/cache/redis/RedisClient.java index 003871ca7..372e3665d 100644 --- a/java/src/main/java/com/genexus/cache/redis/RedisClient.java +++ b/java/src/main/java/com/genexus/cache/redis/RedisClient.java @@ -7,9 +7,9 @@ import java.util.ArrayList; import java.util.List; +import com.fasterxml.jackson.annotation.JsonAutoDetect; import org.apache.commons.lang.StringUtils; -import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; import com.fasterxml.jackson.annotation.PropertyAccessor; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; @@ -79,7 +79,11 @@ private void initCache(String hostOrRedisURL, String password, String cacheKeyPa pool = new JedisPool(new JedisPoolConfig(), host, port, redis.clients.jedis.Protocol.DEFAULT_TIMEOUT, password); objMapper = new ObjectMapper(); - objMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); + objMapper + .setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY) + .setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.NONE) + .setVisibility(PropertyAccessor.SETTER, JsonAutoDetect.Visibility.NONE) + .setVisibility(PropertyAccessor.CREATOR, JsonAutoDetect.Visibility.NONE); objMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); objMapper.enable(SerializationFeature.INDENT_OUTPUT); } diff --git a/java/src/test/java/com/genexus/cache/redis/TestRedisCacheClient.java b/java/src/test/java/com/genexus/cache/redis/TestRedisCacheClient.java index 856886e59..f20d7258d 100644 --- a/java/src/test/java/com/genexus/cache/redis/TestRedisCacheClient.java +++ b/java/src/test/java/com/genexus/cache/redis/TestRedisCacheClient.java @@ -1,5 +1,6 @@ package com.genexus.cache.redis; +import com.genexus.db.CacheValue; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import com.genexus.specific.java.Connect; @@ -10,6 +11,7 @@ import redis.clients.jedis.JedisPool; import java.net.URISyntaxException; +import java.util.concurrent.ThreadLocalRandom; import static org.junit.Assume.assumeTrue; @@ -95,16 +97,30 @@ public void testSetRedis() Assert.assertNotNull("Redis instance could not be created", redis); String cacheId = "TEST"; - String cacheKey = "TEST_KEY"; + String cacheKey = "TEST_KEY" + ThreadLocalRandom.current().nextInt(); String cacheValue = "KeyValue"; redis.set(cacheId, cacheKey, cacheValue); String obtainedValue = redis.get(cacheId, cacheKey, String.class); - Assert.assertEquals(obtainedValue, cacheValue); + } + @Test + public void testSetCacheValueRedis() + { + Connect.init(); + RedisClient redis = getRedisClient("", ""); + Assert.assertNotNull("Redis instance could not be created", redis); + String cacheId = "TEST"+ ThreadLocalRandom.current().nextInt(); + String cacheKey = "TEST_KEY" + ThreadLocalRandom.current().nextInt(); + CacheValue c = new CacheValue("SELECT * FROM User;", new Object[] { 1, 2, 3}); + c.addItem(123); + redis.set(cacheId, cacheKey, c); + CacheValue obtainedValue = redis.get(cacheId, cacheKey, CacheValue.class); + Assert.assertNotNull(obtainedValue); } + }